package net.com.hydroPK.model;

import net.com.hydroPK.*;
import net.com.hydroPK.net.*;
import net.com.hydroPK.io.ActionSender;
import net.com.hydroPK.model.combat.PlayerCombat;
import net.com.hydroPK.model.combat.PlayerMagic;
import net.com.hydroPK.model.combat.PrayerSystem;
import net.com.hydroPK.model.items.PlayerItems;
import net.com.hydroPK.model.items.PlayerWeapon;
import net.com.hydroPK.model.ptrade.PTrade;
import net.com.hydroPK.model.quest.QuestDevelopment;
import net.com.hydroPK.model.skills.PlayerAgility;
import net.com.hydroPK.model.skills.runeCrafting.*;
import net.com.hydroPK.model.skills.Woodcutting;
import net.com.hydroPK.model.skills.herblore.herblore;
import net.com.hydroPK.model.skills.smithing.smithing;
import net.com.hydroPK.net.PlayerSocket;
import net.com.hydroPK.npcs.NPC;
import net.com.hydroPK.util.ByteVector;
import net.com.hydroPK.util.Misc;
import net.com.hydroPK.util.UserInput;


import java.io.*;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;

public class Player implements Entity {
        public void resetSkills() {
	}
        public boolean reportTut = false;
        static public boolean toggleChat1 = false;
    /**
     * Cooking Method
     */
    public void Cook(Player p, int Exp, int Item, int cookedItem, String cookedName) {
	if (Engine.playerItems.HasItemAmount(this, Item, 1) == false) {
		resetSkills();
	} else {
		p.requestAnim(883, 0);
		Engine.playerItems.deleteItem(this, Item, Engine.playerItems.getItemSlot(this, Item), 1);
		Engine.playerItems.addItem(this, cookedItem, 1);
		p.appendExperience(Exp, 7);
		p.getActionSender().sendMessage(this, "You cook the "+ cookedName +".");
		cookTimer = 3;
		cookAmount--;
	}
    }

    /**
     * Cooking Variables
     */
    public int cookTimer = -1;
    public int cookAmount;
    public int cookXP;
    public int cookGet;
    public int cookID;
    public boolean Cooking;
    public String cookName;
    public void appendExperience2(double amount, int skillId) {
        if (!gainCombatXP &&
                ((skillId == 0) || (skillId == 1) || (skillId == 2) || (skillId == 3) || (skillId == 4) || (skillId == 5)
                        || (skillId == 6))) {
            return;
        }
        int oldLvl = getLevelForXP(skillId);
        if (skillXP[skillId] > 200000000) {
            return;
        }
        resetSkills();
        skillXP[skillId] += amount;
        int newLvl = getLevelForXP(skillId);
        if (oldLvl < newLvl) {
            skillLvl[skillId] += (newLvl - oldLvl);
            sendLevelup(skillId);
            requestGFX(1635, 0);
            //requestGFX(199,100);
            appearanceUpdateReq = true;
            updateReq = true;
        }
        actionSender.setSkillLvl(this, skillId);
    }


        public boolean isInterruptable;
        public boolean isBussy;
        public boolean isClayCraft;
        public int threadLeft = 0;
        public void resetAction() {
        this.requestAnim(-1, -1);
        this.isBussy = false;
        this.isInterruptable = false;
        this.isFletching = false;
    }
        /**
     * used for fletching.
     */
    public int[] iteminfo = new int[4];
    public boolean isFletching = false;
    public int fletchingScreenID = -1;
    	/**
	 * Arrays holding the items + their amounts of your bank
	 */
    public int[] bankItems = new int[Engine.playerBank.SIZE];
    public int[] bankItemsN = new int[Engine.playerBank.SIZE];
	/**
	 * The slot at which each bank tab starts at
	 */
	public int[] tabStartSlot = new int[11];
	/**
	 * The amount of items that you have last withrawn/deposited with the X function
	 */
	public int bankX = 50;
	/**
	 * The tab you are viewing, used to store items in it when depositing
	 */
	public int viewingBankTab = 10;
	/**
	 * If you are withrawing items as a note
	 */
	public boolean withdrawNote;
	/**
	 * If you are using insert mode
	 */
	public boolean insertMode;
    public int lastButton = 0;
    public int gotInput = 0;
    public int inputSlot = 0;
    public int nextInput = 0;
    public UserInput uinput = new UserInput(this);
    public UserInput input = new UserInput(this);
    public boolean bankNotes = false;
    public String clanRoom = "";
    public smithing smithing = new smithing();
public int fire = 0;
public int firedelay = 0;
public int objectX = 0;
public int objectY = 0;
public int objectHeight = 0;
public herblore Herb = new herblore(this);
public boolean noteItems = false;

 public void Thieving(Player p, int cashid, int lvlthief, int XPamt, int cashAmt) {
	if (p.skillLvl[17] < lvlthief){
 		p.getActionSender().sendMessage(p, "You need to be level " +lvlthief+ " Thieving for this.");

           return;
      }
	p.clickDelay = 8;
 		p.getActionSender().sendMessage(p, "You Thieve " +cashAmt+ "GP.");
	      Engine.playerItems.addItem(p, cashid, cashAmt);
                    p.appendExperience(XPamt, 17);
	     p.requestAnim(881, 0);
     }


    public boolean playerLoaded = false; // Defence against the resets - Do not delete!
    // -Joshua/hydroPK

    int[] pvpItemsDrops = {13870, 13867, 13873, 13876, 13896, 13884, 13887, 13890, 13893, 14484, 391, 3024,
            157, 145, 1079, 1127, 11283, 6916, 6922, 6889, 1187, 6918, 6914, 6920, 3753, 3749, 3481, 4087,
            3140, 2497, 3140, 2503, 1319, 1215, 5698, 1333, 10776, 10778, 6528, 4757, 4759, 4734, 4736, 4738,
            4745, 4747, 4749, 4751, 4753, 4755, 4714, 4716, 4718, 4720, 4722, 4724, 4726, 4728, 4730, 4732,
            4708, 4710, 4712, 11718, 11722, 11720, 11724, 11726, 6524, 9185, 4151, 4153, 3751, 10828, 1079,
            1127, 11698, 11700, 11730, 2577, 2581, 11732, 1725, 11235, 6731, 6733, 6737, 6735, 385, 11694,
            3144, 560, 1129, 557, 555, 9075, 7060, 139, 11696, 6585, 3105, 10551, 8839, 8840, 8842, 11664,
            11663, 11665, 7462, 7459, 10887, 10499, 14479, 11335, 13864, 13858, 13861, 13905, 11128, 6107,
            6108, 3842, 10887, 10499, 13879, 14479, 11335, 13864, 13858, 13861, 13905, 11128,
            13101, 13263};

    public int barrowsCoords[][] = {
            {3569, 9711}, {3569, 9690}, {3569, 9673},
            {3535, 9674}, {3535, 9691}, {3535, 9717},
            /* THE CHEST */
            {3551, 9691}
    };

    public boolean forceTeleporting = false;
    public boolean needsatarg = false;
    public int ServerMess = 60;
    public int called = 0;
    /*ge variable*/
    public int currentSlot = 0;
    /*waiting in castlewars*/
    public boolean waiting = false;
    public int team = -1;
    public boolean splitChat = true;
    public boolean useingHD = false;
    public int msgTimer = 8;
    public int safeTimer = 10;
    public boolean underAttack = false;
    public boolean inWild = false;
    public boolean safed = false;
    public boolean inLowBounty = false;
    public boolean inMedBounty = false;
    public boolean inHighBounty = false;
    public int turkeydelay = -1;
    public int bountyMaxPlayers = 100;
    public int OptionIdee;
    public boolean arrow = false;
    public boolean updatez = false;
    public int proupdate = 0;
    public int FamiliarType = 0;
    public int FamiliarID = 0;
    public boolean onlinee = false;
    public boolean bountyInterface = false;
    public boolean emoteDelayz = false;
    public boolean swapAsNote = false;
    public boolean DFSSpecial;
    public long lastDFS;
    public boolean movedd = true;
    public int DFSDelay = -1;
    public int member = 0;
    public int Donator;
    public int targetTime = 0;
    public boolean pvpoption2 = false;
    public boolean pvpoption1 = false;
    public int Warning;
    public int muteTimer;
    public boolean bhworld = false;
    public boolean WalkingTo = false;
    public boolean wildWarned = false;
    public boolean followingPlayer = true;
    public boolean followPlayer = true;

    public int barrowsStage = 0;
    public int armadylKills = 0;
    public int bandosKills = 0;
    public int saradominKills = 0;
    public int zamorakKills = 0;

    public void sendGodwarsInterface() {
        //actionSender.setString(this, "0", 601, 0);
        //actionSender.setString(this, "1", 601, 1);
        //actionSender.setString(this, "2", 601, 2);
        //actionSender.setString(this, "3", 601, 3);
        //actionSender.setString(this, "4", 601, 4);
        //actionSender.setString(this, "5", 601, 5);
        actionSender.setString(this, "" + armadylKills, 601, 6);
        actionSender.setString(this, "" + bandosKills, 601, 7);
        actionSender.setString(this, "" + saradominKills, 601, 8);
        actionSender.setString(this, "" + zamorakKills, 601, 9);
        actionSender.setOverlay(this, 601);
    }

    //public int whoiss = BhTarg.whois;
    //public int followPlayer;
    //public int followingPlayer;
    public boolean initialAttack;
    public boolean boltSpecial;
    public String nameSet;
    public int setDrop;
    public boolean pvpoption = true;
    public int KC;
    public int DC;
    public boolean needsarrow = false;
    public String whatsaid;
    public static int Banned = 0;
    public boolean beeninwild = false;
    public int updateTime = 0;
    public List<Long> friends = new ArrayList<Long>(200);
    public List<Long> ignores = new ArrayList<Long>(100);
    /*random pin*/
    public int[] setPin = new int[10];

    public boolean tOverlay = false;
    public boolean tOverlay1 = false;
    public String chatName;
    public final String ACTIVE_CHAT_DEFAULT = "Rune-Resort";
    public String activeChat = ACTIVE_CHAT_DEFAULT;
    public final String ACTIVE_CHAT_OWNER_DEFAULT = "Public Channel";
    public String activeChatOwner = ACTIVE_CHAT_OWNER_DEFAULT;

    public boolean hasBountyAttacker = false;
    public boolean hasOpponent = false;
    public boolean isInBounty = false;
    public int bountyOpponent = 0;
    public String connectionIP = "";
    public String lastConnection = "";
    public int bountyLeaveDelay = 0;
    /**
     * Bounty opps
     */
    public int bountyOpp = 0;

    public boolean bountyArea() {
        return absX >= 3085 && absX <= 3185 && absY >= 3662 && absY <= 3765;
    }

    String[][] itemPrices = {{"Warrior helm", "536"}, {"green dragon", "1000000"}, {"dragon bones", "750000"}, {"Morrigan's javelin", "900000"}, {"Enchanted robe", "495"}, {"Enchanted top", "741"}, {"Enchanted hat", "89"}, {"Adamant knife", "2"}, {"Adamant knife(p)", "4"}, {"Adamant knife(p+)", "5"}, {"Adamant knife(p++)", "13"}, {"Adamant dart", "1"}, {"Adamant dart(p)", "3"}, {"Adamant dart(p+)", "4"}, {"Adamant dart(p++)", "12"}, {"Tzhaar-ket-em", "891"}, {"Barrelchest anchor", "2300"}, {"Crystal bow full", "9000"}, {"Crystal shield full", "9000"}, {"Rune chainbody", "315"}, {"Zamorakian spear", "14395"}, {"Saradomin staff", "800"}, {"Guthix staff", "800"}, {"Zamorak staff", "800"}, {"Bolt rack", "2"}, {"Santa hat", "97000"}, {"Tuna potato", "14"}, {"Wizard boots", "3319"}, {"Regen bracelet", "2570"}, {"Combat bracelet", "137"}, {"Combat bracelet(1)", "137"}, {"Combat bracelet(2)", "137"}, {"Combat bracelet(3)", "137"}, {"Combat bracelet(4)", "137"}, {"Splitbark body", "271"}, {"Splitbark boots", "28"}, {"Splitbark gauntlets", "28"}, {"Splitback helm", "59"}, {"Splitback legs", "240"}, {"Dwarven helmet", "358"}, {"Abyssal whip", "14570"}, {"Fire cape", "10000"}, {"Armadyl godsword", "10000000"}, {"Morrigan's throwing axe", "85000"}, {"Bandos godsword", "100000000"}, {"Saradomin godsword", "100000000"}, {"Zamorak godsword", "100000000"}, {"Dragon med helm", "885"}, {"Dragon sq shield", "5630"}, {"Dragon dagger", "292"}, {"Dragon dagger(p)", "305"}, {"Dragon dagger(p+)", "312"}, {"Drag dagger(p++)", "350"}, {"Dragon spear", "451"}, {"Dragon spear(p)", "460"}, {"Dragon spear(p+)", "465"}, {"Dragon spear(p++)", "506"}, {"Dragon longsword", "956"}, {"Dragon battleaxe", "1200"}, {"Dragon mace", "298"}, {"Dragon claws", "243322322"}, {"Dragon chainbody", "50565"}, {"Dragon halberd", "1948"}, {"Dragon platelegs", "6323"}, {"Dragon plateskirt", "1979"}, {"Dragon scimitar", "998"}, {"Dragon platebody", "277832"}, {"Dragon axe", "16880"}, {"Dragon 2h sword", "8921"}, {"Dragon bolts (e)", "46"}, {"Diamond bolts (e)", "8"}, {"Dragon arrow", "29"}, {"Dragon arrow(p)", "31"}, {"Dragon arrow(p+)", "32"}, {"Dragon arrow(p++)", "40"}, {"Dragon fire arrows", "26"}, {"Dragonfire shield", "177038"}, {"Dragon full helm", "125349"}, {"Dragon boots", "2407"}, {"Dragon dart", "6"}, {"Dragon dart(p)", "8"}, {"Dragon dart(p+)", "9"}, {"Dragon dart(p++)", "17"}, {"Dragon bones", "24"}, {"Big bones", "3"}, {"Astral rune", "1"}, {"Blood rune", "3"}, {"Death rune", "3"}, {"Law rune", "3"}, {"Nature rune", "2"}, {"Soul rune", "3"}, {"Rune arrow", "2"}, {"Rune arrow(p)", "4"}, {"Rune arrow(p+)", "5"}, {"Rune arrow(p++)", "13"}, {"Rune fire arrows", "2"}, {"Rune c'bow", "95"}, {"Rune dart", "2"}, {"Rune dart(p)", "4"}, {"Rune dart(p+)", "5"}, {"Rune dart(p++)", "13"}, {"Rune fire arrows", "2"}, {"Rune full helm (t)", "3160"}, {"Rune full helm(g)", "4792"}, {"Rune kiteshield (g)", "4307"}, {"Rune kiteshield (t)", "2838"}, {"Rune platebody (g)", "6296"}, {"Rune platebody (t)", "3995"}, {"Rune platelegs (g)", "6296"}, {"Rune platelegs (t)", "2076"}, {"Rune plateskirt (g)", "639"}, {"Rune plateskirt (t)", "569"}, {"Rune full helm", "211"}, {"Rune boots", "460"}, {"Rune kiteshield", "499"}, {"Rune med helm", "114"}, {"Rune platebody", "578"}, {"Rune platelegs", "507"}, {"Rune plateskirt", "443"}, {"Rune sq shield", "230"}, {"Rune thrownaxe", "3"}, {"Gilded full helm", "3957"}, {"Gilded kiteshield", "4460"}, {"Gilded platebody", "15019"}, {"Gilded platelegs", "5902"}, {"Gilded plateskirt", "1618"}, {"Guthix full helm", "38888"}, {"Guthix kiteshield", "3763"}, {"Guthix platebody", "6185"}, {"Guthix platelegs", "2935"}, {"Guthix plateskirt", "577"}, {"Saradomin full", "8430"}, {"Saradomin kite", "8776"}, {"Saradomin plate", "16213"}, {"Saradomin legs", "3694"}, {"Saradomin skirt", "1003"}, {"Zamorak full helm", "5814"}, {"Zamorak kiteshield", "6221"}, {"Zamorak platebody", "11047"}, {"Zamorak platelegs", "3534"}, {"Zamorak plateskirt", "991"}, {"Adam full helm(g)", "1121"}, {"Adam full helm(t)", "601"}, {"Adam kiteshield (g)", "1159"}, {"Adam kiteshield (t)", "414"}, {"Adam platebody (g)", "2009"}, {"Adam platebody (t)", "908"}, {"Adam platelegs (g)", "792"}, {"Adam plateskirt (t)", "152"}, {"Adamant arrow", "1"}, {"Adamant arrow(p)", "3"}, {"Adamant arrow(p+)", "4"}, {"Adamant arrow(p++)", "12"}, {"Adamant fire arrows", "9"}, {"Adamant javelin", "1"}, {"Adamant javelin(p)", "3"}, {"Adamant javelin(p+)", "4"}, {"Adamant javelin(p++)", "12"}, {"Adamant chainbody", "27"}, {"Adamant boots", "20"}, {"Adamant full helm", "23"}, {"Adamant kiteshield", "31"}, {"Adamant platebody", "98"}, {"Adamant platelegs", "37"}, {"Adamant plateskirt", "37"}, {"Adamant med helm", "12"}, {"Adamant thrownaxe", "1"}, {"Adamant spear", "10"}, {"Adamant spear(p)", "20"}, {"Adamant spear(p+)", "25"}, {"Adamant spear(p++)", "66"}, {"Spined boots", "36"}, {"Spined gloves", "17"}, {"Spined body", "45"}, {"Spined chaps", "21"}, {"Spined helm", "358"}, {"Rock-shell boots", "11"}, {"Rock-shell gloves", "28"}, {"Rock-shell helm", "209"}, {"Rock-shell legs", "486"}, {"Rock-shell plate", "397"}, {"Skeletal boots", "194"}, {"Skeletal bottoms", "238"}, {"Skeletal gloves", "432"}, {"Skeletal helm", "58"}, {"Skeletal top", "267"}, {"Archers ring", "5783"}, {"Berserker ring", "18367"}, {"Seer's ring", "599"}, {"Warrior ring", "1163"}, {"Toktz-xil-ul", "3"}, {"Toktz-ket-xil", "2108"}, {"Toktz-mej-tal", "1092"}, {"Toktz-xil-ak", "1231"}, {"Toktz-xil-ek", "739"}, {"Toktz-ket-em", "935"}, {"Tzhaar-ket-om", "1579"}, {"Obsidian cape", "1864"}, {"Berserker necklace", "1787"}, {"Granite maul", "1458"}, {"Granite body", "490"}, {"Granite helm", "274"}, {"Granite legs", "1999"}, {"Granite shield", "348"}, {"Amulet of defence", "7"}, {"Amulet of fury", "25823"}, {"Amulet of glory", "386"}, {"Amulet of glory(1)", "386"}, {"Amulet of glory(2)", "386"}, {"Amulet of glory(3)", "386"}, {"Amulet of glory(4)", "386"}, {"Amulet of glory(t)", "2090"}, {"Amulet of glory(t1)", "2090"}, {"Amulet of glory(t2)", "2090"}, {"Amulet of glory(t3)", "2090"}, {"Amulet of glory(t4)", "2090"}, {"Amulet glory(t2)", "2090"}, {"Amulet glory(t3)", "2090"}, {"Amulet glory(t4)", "2090"}, {"Amulet of magic", "5"}, {"Amulet of magic(t)", "1042"}, {"Amulet of power", "31"}, {"Amulet of strength", "15"}, {"3rd age amulet", "561623"}, {"Strength amulet(t)", "5439"}, {"Antipoison(1)", "1"}, {"Antipoison(2)", "3"}, {"Antipoison(3)", "4"}, {"Antipoison(4)", "5"}, {"Antipoison+(1)", "23"}, {"Antipoison+(2)", "45"}, {"Antipoison+(3)", "68"}, {"Antipoison+(4)", "90"}, {"Antipoison++(1)", "37"}, {"Antipoison++(2)", "74"}, {"Antipoison++(3)", "110"}, {"Antipoison++(4)", "147"}, {"Super attack(1)", "2"}, {"Super attack(2)", "4"}, {"Super attack(3)", "5"}, {"Super attack(4)", "7"}, {"Super strength(1)", "10"}, {"Super strength(2)", "20"}, {"Super strength(3)", "30"}, {"Super strength(4)", "40"}, {"Super defence(1)", "2"}, {"Super defence(2)", "4"}, {"Super defence(3)", "5"}, {"Super defence(4)", "8"}, {"Saradomin brew(1)", "7"}, {"Saradomin brew(2)", "15"}, {"Saradomin brew(3)", "22"}, {"Saradomin brew(4)", "29"}, {"Zamorak brew(1)", "12"}, {"Zamorak brew(2)", "24"}, {"Zamorak brew(3)", "36"}, {"Zamorak brew(4)", "48"}, {"Super restore(1)", "36"}, {"Super restore(2)", "72"}, {"Super restore(3)", "108"}, {"Super restore(4)", "144"}, {"Super antipoison(1)", "3"}, {"Super antipoison(2)", "6"}, {"Super antipoison(3)", "9"}, {"Super antipoison(4)", "11"}, {"Prayer potion(1)", "21"}, {"Prayer potion(2)", "42"}, {"Prayer potion(3)", "64"}, {"Prayer potion(4)", "85"}, {"3rd age mage hat", "406772"}, {"3rd age robe", "422061"}, {"3rd age robe top", "644626"}, {"3rd age full helmet", "559838"}, {"3rd age kiteshield", "848461"}, {"3rd age platebody", "849293"}, {"3rd age platelegs", "757609"}, {"3rd age range coif", "282814"}, {"3rd age range legs", "427202"}, {"3rd age range top", "501644"}, {"3rd age vambraces", "210575"}, {"Ahrim's hood", "608"}, {"Ahrim's robeskirt", "7747"}, {"Ahrim's robetop", "3582"}, {"Ahrim's staff", "511"}, {"Torag's hammers", "960"}, {"Torag's helm", "4919"}, {"Torag's platebody", "2196"}, {"Torag's platelegs", "3563"}, {"Karil's coif", "428"}, {"Karil's crossbow", "1265"}, {"Karil's leatherskirt", "2165"}, {"Karil's leathertop", "11627"}, {"Dharok's greataxe", "2181"}, {"Dharok's helm", "32601"}, {"Dharok's platebody", "2247"}, {"Dharok's platelegs", "3242"}, {"Verac's brassard", "2181"}, {"Verac's flail", "1592"}, {"Verac's helm", "19233"}, {"Verac's plateskirt", "5590"}, {"Guthan's chainskirt", "2090"}, {"Guthan's helm", "21675"}, {"Guthan's platebody", "2160"}, {"Guthan's warspear", "13720"}, {"Saradomin sword", "71022"}, {"Ava's accumulator", "113"}, {"Archer helm", "553"}, {"Berserker helm", "773"}, {"Farseer helm", "536"}, {"Helm of neitiznot", "521"}, {"Infinity boots", "8277"}, {"Infinity bottoms", "3089"}, {"Infinity gloves", "1957"}, {"Infinity hat", "6382"}, {"Infinity top", "4317"}, {"Master wand", "4265"}, {"Teacher wand", "432"}, {"Mage's book", "19198"}, {"Initiate cuisse", "47"}, {"Initiate hauberk", "59"}, {"Initiate sallet", "34"}, {"Proselyte cuisse", "61"}, {"Proselyte hauberk", "75"}, {"Proselyte sallet", "46"}, {"Proselyte tasset", "61"}, {"Bandos boots", "8567"}, {"Bandos chestplate", "137022"}, {"Bandos tassets", "119478"}, {"Armadyl chestplate", "110821"}, {"Armadyl helmet", "48086"}, {"Armadyl plateskirt", "119685"}, {"Black d' body", "80"}, {"Black d' chaps", "62"}, {"Black d' vamb", "25"}, {"Zamorak d'", "12302"}, {"Zamorak chaps", "1175"}, {"Zamorak bracers", "5754"}, {"Zamorak coif", "2072"}, {"Saradomin d'", "9908"}, {"Saradomin chaps", "1005"}, {"Saradomin bracers", "4112"}, {"Saradomin coif", "1172"}, {"Guthix chaps", "279"}, {"Guthix coif", "1044"}, {"Guthix dragon", "949"}, {"Guthix bracers", "138"}, {"Guthix cloak", "6229"}, {"Guthix crozier", "29"}, {"Guthix mitre", "972"}, {"Guthix mjolnir", "60"}, {"Guthix robe legs", "993"}, {"Guthix robe top", "1095"}, {"Guthix stole", "144"}, {"Zamorak cloak", "10332"}, {"Zamorak crozier", "54"}, {"Zamorak mitre", "1382"}, {"Zamorak mjolnir", "91"}, {"Zamorak robe legs", "1626"}, {"Zamorak robe top", "1967"}, {"Zamorak stole", "864"}, {"Saradomin cloak", "9206"}, {"Saradomin crozier", "51"}, {"Saradomin mitre", "1634"}, {"Saradomin mjolnir", "113"}, {"Saradomin robe legs", "1071"}, {"Saradomin robe top", "1242"}, {"Saradomin stole", "650"}, {"Dark bow", "7900"}, {"Blue partyhat", "888888888"}, {"Green partyhat", "888888888"}, {"Purple partyhat", "888888888"}, {"Red partyhat", "1173043"}, {"White partyhat", "888888888"}, {"Yellow partyhat", "888888888"}, {"Blue h'ween mask", "777777777"}, {"888888888", "102486"}, {"Red h'ween mask", "888888888"}, {"Scythe", "273844"}, {"Bunny ears", "170376"}, {"Easter egg", "46282"}, {"Pumpkin", "53056"}, {"Manta ray", "16"}, {"Shark", "8"}, {"Cooked karambwan", "6"}, {"Rune knife", "5"}, {"Rune knife(p)", "7"}, {"Rune knife(p+)", "8"}, {"Rune knife(p++)", "16"}, {"Attack cape(t)", "990"}, {"Attack cape(t)", "990"}, {"Attack hood", "10"}, {"Strength cape", "990"}, {"Strength cape(t)", "990"}, {"Strength hood", "10"}, {"Defence cape", "990"}, {"Defence cape(t)", "990"}, {"Defence hood", "10"}, {"Ranging cape", "990"}, {"Ranging cape(t)", "990"}, {"Ranging hood", "10"}, {"Prayer cape", "990"}, {"Prayer cape(t)", "990"}, {"Prayer hood", "10"}, {"Magic cape", "990"}, {"Magic cape(t)", "990"}, {"Magic hood", "10"}, {"Runecraft cape", "990"}, {"Runecraft cape(t)", "990"}, {"Runecrafting hood", "10"}, {"Hitpoints cape", "990"}, {"Hitpoints cape(t)", "990"}, {"Hitpoints hood", "10"}, {"Agility cape", "990"}, {"Agility cape(t)", "990"}, {"Agility hood", "10"}, {"Herblore cape", "990"}, {"Herblore cape(t)", "990"}, {"Herblore hood", "10"}, {"Thieving cape", "990"}, {"Thieving cape(t)", "990"}, {"Thieving hood", "10"}, {"Crafting cape", "990"}, {"Crafting cape(t)", "990"}, {"Crafting hood", "10"}, {"Fletching cape", "990"}, {"Fletching cape(t)", "990"}, {"Fletching hood", "10"}, {"Slayer cape", "990"}, {"Slayer cape(t)", "990"}, {"Slayer hood", "10"}, {"Construct. cape", "990"}, {"Construct. cape(t)", "990"}, {"Construct. hood", "10"}, {"Mining cape", "990"}, {"Mining cape(t)", "990"}, {"Mining hood", "10"}, {"Smithing cape", "990"}, {"Smithing cape(t)", "990"}, {"Smithing hood", "10"}, {"Fishing cape", "990"}, {"Fishing cape(t)", "990"}, {"Fishing hood", "10"}, {"Cooking cape", "990"}, {"Cooking cape(t)", "990"}, {"Cooking hood", "10"}, {"Firemaking cape", "990"}, {"Firemaking cape(t)", "990"}, {"Firemaking hood", "10"}, {"Woodcutting cape", "990"}, {"Woodcut. cape(t)", "990"}, {"Woodcutting hood", "10"}, {"Magic logs", "16"}, {"Runite ore", "137"}, {"Farming cape", "990"}, {"Farming cape(t)", "990"}, {"Morrigan's Javelin", "18222100"}, {"Farming hood", "10"}, {"Quest point cape", "990"}, {"Quest point hood", "10"}, {"Summoning cape", "990"}, {"Summoning cape(t)", "990"}, {"Summoning hood", "10"}, {"Robin hood hat", "20395"}, {"Ranger boots", "66372"}, {"Arcane spirit shield", "1533295"}, {"Blessed spirit shield", "41387"}, {"Divine spirit shield", "2113049"}, {"Elysian spirit shield", "2515283"}, {"Spectral spirit shield", "1552932"}, {"Spirit shield", "626"}, {"Statius Hammer", "223222222"}, {"Vesta's longsword", "63180"}};

    String[][] killPrices = {{"Void knight top", "15"}, {"Dragon claws", "35"}, {"Void knight robe", "15"}, {"Void knight mace", "10"}, {"Void knight gloves", "5"}, {"Void mage helm", "10"}, {"Void ranger helm", "10"}, {"Void melee helm", "10"}, {"Runner hat", "10"}, {"Healer hat", "10"}, {"Ranger hat", "10"}, {"Dwarf remains", "1638634"}, {"Runner boots", "10"}, {"Penance gloves", "10"}, {"Penance skirt", "10"}, {"Fighter torso", "15"}, {"Zuriels", "10"}, {"Zuriel's hood", "10"}, {"Vesta's longsword", "10"}, {"Statius's warhammer", "10"}, {"Statius's platelegs", "10"}, {"Statius's platebody", "10"}, {"Statius's full helm", "10"}, {"Vesta's plateskirt", "10"}, {"Vesta's chainbody", "10"}, {"Fire cape", "40"}};

    int[][] otherPrices = {{7653, 1}, {7454, 1}, {7455, 1}, {7456, 3}, {7457, 5}, {7458, 10}, {7459, 15}, {7460, 20}, {7461, 1000}, {7462, 1000}, {4097, 59}, {4107, 153}, {4117, 61}, {4105, 59}, {4115, 59}, {4095, 58}, {4099, 92}, {4109, 118}, {4089, 145}, {4093, 482}, {4103, 478}, {4113, 480}, {4091, 721}, {4101, 720}, {4111, 720}};

    int[][] killRequirments = {{8844, 1}, {8845, 3}, {8846, 5}, {8847, 10}, {8848, 15}, {8849, 20}, {8850, 25}, {10887, 5}, {4214, 10}, {4225, 10}, {2412, 5}, {2413, 5}, {2414, 5}, {2415, 5}, {2416, 5}, {2417, 5}, {7453, 0}, {7454, 0}, {7455, 1}, {7456, 3}, {7457, 5}, {7458, 10}, {7459, 15}, {7460, 20}, {7461, 20}, {7462, 25}};

    public int getItemValue(int item) {
        if (item == 995) {
            return 1;
        }
        int value = 0;
        for (String[] s : itemPrices) {
            String name = Engine.items.getItemName(item);
            if (name.equals(s[0])) {
                value = 100 * Integer.parseInt(s[1]);
            }
        }
        for (int[] i : otherPrices) {
            if (item == i[0]) {
                value = 100 * i[1];
            }
        }
        if (Engine.items.stackable(item) && value == 0) {
            value = 1;
        }
        return value;
    }

    /**
     * Pm void
     */
    public void friendsLoggedIn() {
        for (Long friend : friends) {
            actionSender.sendFriend(this, friend, getWorld(friend));
        }
        long[] array = new long[ignores.size()];
        int i = 0;
        for (Long ignore : ignores) {
            if (ignore != null)
                array[i++] = ignore;
        }
        actionSender.sendIgnores(this, array);
        long me = Misc.stringToLong(username);
        for (Player p : Engine.players) {
            if (p == null) continue;
            if (p.friends.contains(me)) {
                p.actionSender.sendFriend(p, me, 66);
            }
        }
    }

    public int getWorld(long friend) {
        for (Player p : Engine.players) {
            if (p != null && p.online) {
                if (Misc.stringToLong(p.username) == friend) {
                    return 1;
                }
            }
        }
        return 0;
    }

    public int getKillRequirment(int item) {
        int requirment = 0;
        for (int[] i : killRequirments) {
            if (item == i[0]) {
                requirment = i[1];
            }
        }
        return requirment;
    }

    public int getKillCost(int item) {
        int cost = 0;
        for (String[] s : killPrices) {
            String name = Engine.items.getItemName(item);
            if (name.equals(s[0])) {
                cost = Integer.parseInt(s[1]);
            }
        }
        return cost;
    }

    public double PVPPotential;

    public int totalKills;
    public int kills;

    public void message(String message) {
        actionSender.sendMessage(this, message);
    }

    public boolean jailed;
    public int jailTimer;
    public boolean teleblocked;
    public int teleblockTimer = 500;
    public boolean profollow = false; //follow
    public boolean teletab;
    public int leverTeleportX;
    public int leverTeleportY;
    public int leverTeleportH;
    public int leverTeleportDelay = -1;
    public int casttdelay = 0;

    public boolean hitOne;
    public boolean hitTwo;
    public boolean hitThree;
    public boolean hitFour;
    public double hit1;
    public double hit2;
    public double hit3;
    public double hit4;

    public void sleep(int i)
    {
        try
        {
            long l = System.currentTimeMillis();
            Thread.sleep(i);
            long l1;
            while(l + (long)i > (l1 = System.currentTimeMillis()))
            {
                Thread.sleep((l + (long)i) - l1);
            }
        }
        catch(InterruptedException interruptedexception)
        {
            interruptedexception.printStackTrace();
        }
    }


    /* For toggling combat XP on/off */
    public boolean gainCombatXP = true;

    public void toggleCombatXP() {
        toggleCombatXP(!gainCombatXP);
    }

    public void toggleCombatXP(boolean flag) {
        gainCombatXP = flag;
        message((flag ? "You toggle combat xp. You will now receive NO combat xp when fighting."
                : "You toggle combat xp. You will now receive combat xp when fighting."));
    }

    public void WalkingTo(int i, int j) {
        getActionSender().sendMessage(this, "F");
    }


    public int specials;

    public int spendingExperience = 6000000;

    public int degrade = 6000;
    public boolean degrades = degrade < 6000;

    /*Reputation system*/
    public int playerRep = 0;
    public int givenRep;
    public int repTimer;
    public int votetimer;

    //Combat variables

    public double rangedMax;

    public int attackedByCount;
    public String attacking;

//	Player p3 = Engine.players[this.target];
//	public String targetname = ""+whoiss+"";

    public String attackedBy;

    public boolean needsTarg = false;
    public int spell;
    public int spell2;
    public int cuedSpell;
    public int cuedSpells;
    public int magicOppIndex;
    public int graphicMSDelay;
    public int magicGraphicDelay = -1;
    public int magicDamageDelay = -1;
    public int magicAffectDelay = -1;
    public boolean successfulCast;
    public boolean usingMage;
    public boolean orb;
    public int target;
    public String tName = "" + this.target + "";
    public int weapon;
    public int strengthBonus;
    public int oppIndex;
    public int hitIndex;

    public int magicNpcIndex;
    public int magicNpcSpell;
    public int magicNpcSpellbook;
    public int magicGraphicDelayNpc;
    public int magicDamageDelayNpc;
    public int magicEffectDelayNpc;
    public int graphicMSDelayNpc;

    public void resetMagicNpc() {
        magicNpcIndex = -1;
        magicNpcSpell = -1;
        magicNpcSpellbook = -1;
        magicGraphicDelayNpc = -1;
        magicDamageDelayNpc = -1;
        magicEffectDelayNpc = -1;
        graphicMSDelayNpc = -1;
    }

    // Easier to use than equipment[0], equipment[1] etc
    public int hatNum = 0;
    public int capeNum = 1;
    public int amuletNum = 2;
    public int weaponNum = 3;
    public int chestNum = 4;
    public int shieldNum = 5;
    public int legsNum = 7;
    public int handsNum = 9;
    public int feetNum = 10;
    public int ringNum = 12;
    public int arrowsNum = 13;

    public boolean getExperience = true;

    public PTrade pTrade;

    public void statSpy(Player other) {
        int[] strings = {1, 25, 13, 5, 37, 49, 61, 45, 69, 65, 33, 57, 53, 21, 9, 29, 17, 41, 77, 81, 73, 85, 89, 93};
        actionSender.setString(this, other.username.substring(0, 1).toUpperCase() + other.username.substring(1), 523, 99);
        for (int i = 0; i < strings.length; i++) {
            actionSender.setString(this, "" + other.skillLvl[i], 523, strings[i]);
            actionSender.setString(this, "" + other.getLevelForXP(i), 523, strings[i] + 1);
        }
        actionSender.setTab(this, 79, 523);
    }

    public void walkTo(int absX, int absY) {
        int i = absX - (this.mapRegionX - 6) * 8;
        int j = absY - (this.mapRegionY - 6) * 8;
        Server.engine.playerMovement.resetWalkingQueue(this);
        Server.engine.playerMovement.addToWalkingQueue(this, i, j);
        this.appearanceUpdateReq = true;
        this.updateReq = true;
    }

    public void clearItem(int item) {
        for (int i = 0; i < bankItems.length; i++) {
            if (item == bankItems[i]) {
                bankItems[i] = -1;
                bankItemsN[i] = 0;
            }
        }
        for (int i = 0; i < equipment.length; i++) {
            if (item == equipment[i]) {
                equipment[i] = -1;
                equipmentN[i] = 0;
            }
        }
        for (int i = 0; i < items.length; i++) {
            if (item == items[i]) {
                items[i] = -1;
                itemsN[i] = 0;
            }
        }
    }

    public void clearItem(String item) {
        String name = item;
        for (int i = 0; i < bankItems.length; i++) {
            if (name.equals(Engine.items.getItemName(bankItems[i]))) {
                bankItems[i] = -1;
                bankItemsN[i] = 0;
            }
        }
        for (int i = 0; i < equipment.length; i++) {
            if (name.equals(Engine.items.getItemName(equipment[i]))) {
                equipment[i] = -1;
                equipmentN[i] = 0;
            }
        }
        for (int i = 0; i < items.length; i++) {
            if (name.equals(Engine.items.getItemName(items[i]))) {
                items[i] = -1;
                itemsN[i] = 0;
            }
        }
    }

    public boolean GWDD;
    public boolean lever;

    public void leverTeleport(String location) {
        if (teleblocked) {
            actionSender.sendMessage(this, "You are teleport blocked!");
            return;
        }
        int x = absX;
        int y = absY;
        int h = heightLevel;
        if (location != null) {
            if (location.equals("Deep Wilderness")) {
                x = 3153;
                y = 3923;
            }
            if (location.equals("Ardougne Lever")) {
                x = 2561;
                y = 3311;
            }
            if (location.equals("Mage Bank (Inside)")) {
                x = 2539;
                y = 4712;
            }
            if (location.equals("Mage Bank (Outside)")) {
                x = 3092;
                y = 3961;
            }
        }
        actionSender.removeShownInterface(this);
        requestAnim(2140, 0);
        leverTeleportX = x;
        leverTeleportY = y;
        leverTeleportH = h;
        leverTeleportDelay = 2;
        lever = true;
    }

    public void teletab(String city) {
        int x = absX;
        int y = absY;
        int h = heightLevel;
        int r = 0;
        teletab = true;
        if (city != null) {
            if (city.equals("Varrock")) {
                x = 2726;
                y = 3492;
                r = 0;
            }
            if (city.equals("Lumbridge")) {
                x = 3087;
                y = 3502;
                r = 0;
            }
            if (city.equals("House")) {
                x = 3217;
                y = 3218;
                r = 0;
            }
            if (city.equals("Camelot")) {
                x = 3087;
                y = 3502;
                r = 0;
            }
            if (city.equals("Ardougne")) {
                x = 2660;
                y = 3301;
                r = 4;
            }
        }
        actionSender.removeShownInterface(this);
        x += getRandom(r);
        y += getRandom(r);
        teleportTo(x, y, h, 3, 0, 9597, 4071, 1680, 0, 678, 0);
    }


    public void reqWalkQueue(int x, int y) {
        int firstX = x - (mapRegionX - 6) * 8;
        int firstY = y - (mapRegionY - 6) * 8;
        Engine.playerMovement.resetWalkingQueue(this);
        Engine.playerMovement.addStepToWalkingQueue(firstX, firstY, this);
        Engine.playerMovement.addStepToWalkingQueue(firstX, firstY + 1, this);
        Engine.playerMovement.addStepToWalkingQueue(firstX, firstY + 2, this);
    }

    public void reqWalkQueueBack(int x, int y) {
        int firstX = x - (mapRegionX - 6) * 8;
        int firstY = y - (mapRegionY - 6) * 8;
        Engine.playerMovement.resetWalkingQueue(this);
        Engine.playerMovement.addStepToWalkingQueue(firstX, firstY, this);
        Engine.playerMovement.addStepToWalkingQueue(firstX, firstY - 1, this);
        Engine.playerMovement.addStepToWalkingQueue(firstX, firstY - 2, this);
    }

    public boolean usingRange() {
        int[] bows = {806, 807, 808, 809, 841, 810, 811, 11230, 863, 13883, 13879, 864, 865, 866, 867, 868, 869, 861, 4214,
                4734, 9185, 11235};
        for (int i : bows) {
            if (this.equipment[3] == i) {
                return true; // FML PLS
            }
        }
        return false;
    }

    public void cityTeleport(String city) {
        int x = absX;
        int y = absY;
        int h = heightLevel;
        int r = 0;
        if (city != null) {
            if (city.equals("Varrock")) {
                x = 3210;
                y = 3421;
                r = 4;
                h = 0;
            }
            if (city.equals("Lumbridge")) {
                x = 3221;
                y = 3218;
                r = 2;
                h = 0;
            }
            if (city.equals("Falador")) {
                x = 2964;
                y = 3378;
                r = 3;
                h = 0;
            }
            if (city.equals("Camelot")) {
                x = 2756;
                y = 3476;
                r = 3;
                h = 0;
            }
            if (city.equals("Ardougne")) {
                x = 2660;
                y = 3301;
                r = 4;
                h = 0;
            }
            if (city.equals("Edgeville")) {
                x = 2440;
                y = 3090;
                r = 0;
                h = 0;
            }
        }
        actionSender.removeShownInterface(this);
        x += getRandom(r);
        y += getRandom(r);
        teleportTo(x, y, h, 4, 0, 8939, 8941, 1576, 0, 1577, 0);
    }

    public boolean isPVP() {
        return true;
    }
    public boolean isNormal() {
        return heightLevel == 0 || heightLevel == 5;
    }

    public boolean hotZone(int x, int y) {
	    if ((x >= 1675 && x <= 1718 && y >= 5604 && y <= 5595)) //Home
        if ((x >= 3205 && x <= 3222 && y >= 3420 && y <= 3438)) //Varrock
        if ((x >= 3231 && x <= 3238 && y >= 3212 && y <= 3225)) //Lumbridge
        if ((x >= 2949 && x <= 2978 && y >= 3367 && y <= 3391)) //Falador
        if ((x >= 2741 && x <= 2774 && y >= 3464 && y <= 3481)) //Camelot
        if ((x >= 2652 && x <= 2672 && y >= 3294 && y <= 3318)) //Ardougne
        if ((x >= 3082 && x <= 3090 && y >= 3483 && y <= 3501)) //Edgeville
        if ((x >= 3181 && x <= 3180 && y >= 3509 && y <= 3508)) { //GE
            return true;
        }
        return false;
    }

    public void Welcome1() {

        if (this == null || this.disconnected[0]) {
            return;
        }
        requestGFX(1844, 18000);
        clearItem("null");
        clearItem("partyhat");
        clearItem("Blue_partyhat");
        clearItem("Green_partyhat");
        clearItem("Red_partyhat");
        clearItem("Purple_partyhat");
        clearItem("White_partyhat");
        clearItem("Yellow_partyhat");
        clearItem("Blue_partyhat");
        clearItem("Green_partyhat");
        clearItem("Red_partyhat");
        clearItem("Purple_partyhat");
        clearItem("White_partyhat");
        clearItem("Yellow_partyhat");
        actionSender.setWindowPane(this, 549);
        actionSender.setInterface(this, 1, 549, 2, 378);
        actionSender.setInterface(this, 1, 549, 3, 17);
        actionSender.setString(this, "*", 17, 0);
        actionSender.setString(this, "My Server!", 17, 3);
        actionSender.setString(this, "*", 378, 37);
        actionSender.setString(this, "*", 378, 39);
        actionSender.setString(this, "900m days of member credit", 378, 94);
        actionSender.setString(this, "You have 900m days of member credit remaining.", 378, 93);
        actionSender.setString(this, "*", 378, 38);
        actionSender.setString(this, "*", 378, 96);
        actionSender.setString(this, "Welcome to My Server.", 378, 115);
        actionSender.setString(this, "*", 378, 116);

        if (this == null || this.disconnected[0]) {
            return;
        }
        requestGFX(1844, 18000);
        clearItem("null");
        clearItem("Blue_partyhat");
        clearItem("Green_partyhat");
        clearItem("Red_partyhat");
        clearItem("Purple_partyhat");
        clearItem("White_partyhat");
        clearItem("Yellow_partyhat");
        clearItem("Blue_partyhat");
        clearItem("Green_partyhat");
        clearItem("Red_partyhat");
        clearItem("Purple_partyhat");
        clearItem("White_partyhat");
        clearItem("Yellow_partyhat");
        /*this.pvpoption1 = true;
        this.actionSender.setString(this, "Select Your World", 557, 1);
        this.optionArray[2] = true;
        this.actionSender.setString(this, "PvP World - Safe Zones", 557, 2);
        this.pvpoption2 = true;
        this.actionSender.setString(this, "Safe World - All Safe", 557, 3);
        this.actionSender.showChatboxInterface(this, 557);
        this.pvpoption = true;*/

        //System.out.println(this.tempHeight2);
        setCoords(this.absX, this.absY, this.tempHeight2); // Sets height to loaded height
    }

    public boolean teleportTo(int x, int y, int height) {
        if (teleportTo(x, y, height, 4, 0, 8939, 8941, 1576, 0, 1577, 0))
            return true;
        return false;
    }

    public boolean teleportTo(int x, int y, int height, boolean flag) {
        forceTeleporting = flag;
        if (teleportTo(x, y, height, 4, 0, 8939, 8941, 1576, 0, 1577, 0))
            return true;
        return false;
    }

    public void sendBarrowsOverlay(int killcount) {
        actionSender.setString(this, "Kill Count : " + killcount, 24, 0);
        actionSender.setOverlay(this, 24);
    }

    public String getKillMessage(String player) {
        String[][] selection = {{"It's official: you are far more awesome than ", " is."},
                {"Let all warriors learn from the fate of ", " and fear you."},
                {"Well done, you've pwned ", "."},
				{"Watch", "Tremble in the sight of masturbation."},
                {"Woah u just fucked, ", " up they are probably having an orgasm."},
                {"What a vagina", " is they just got owned."},
                {"You have cummed all over ", "'s face."},
                {"Ooh, ", " got owned congratz on killin them!"},
                {"", " has been shot by fireend because you owned them."},
                {"You have proven your superiority over ", "."}};
        int index = (int) Math.floor(Math.random() * 9);
        return selection[index][0] + player + selection[index][1];
    }

    public boolean multiwayCombatZone(int x, int y) {
        if ((x >= 3223 && y >= 3631 && x <= 3342 && y <= 3739/*Clan Wars*/)

                ) {
            return false;
        }
        if ((x > 3157 && x < 3176 && y > 9752 && y < 9765)/* Black drags multi */) {
            return true;
        }
        return false;
    }

    public boolean timerStarted;
    public long PVPTimer;

    public boolean GWDD(int x, int y) {
        GWDD = true;
        return (x >= 2811 && x <= 2947 && y >= 0000 && y <= 5365);

    }

    public boolean funPkZone(int x, int y) {
        if (x >= 3120 && x <= 3148 && y >= 3613 && y <= 3640) {
            // Stealing creations lobby
            return true;
        }
        return false;
    }

    public boolean wildernessZone(int x, int y) {//safezones
        if ((x >= 3091 && x <= 3098 && y >= 3488 && y <= 3499) ||
                (x >= 2355 && x <= 2448 && y >= 3061 && y <= 3146) || //HOME
                (x >= 3089 && x <= 3157 && y >= 9864 && y <= 9981) || //new dungeon
                (x >= 2304 && x <= 2363 && y >= 3504 && y <= 3555) || //bork area
                (x >= 3351 && x <= 3388 && y >= 3262 && y <= 3281) || //duel areana
                (x >= 3175 && x <= 3193 && y >= 9741 && y <= 9773) || //clan battles pt. 1
                (x >= 2974 && x <= 2999 && y >= 9622 && y <= 9650) || //dproom
                (x >= 2584 && x <= 2603 && y >= 5257 && y <= 5270) || //zamorak lair
                (x >= 3021 && x <= 3072 && y >= 9539 && y <= 9560) || //saradomin lair
	(x >= 3260 && x <= 3309 && y >= 3151 && y <= 3185) || //Al-Kharid
	(x >= 3351 && x <= 3364 && y >= 2946 && y <= 2961) || //Bar Location
                (x >= 2652 && x <= 2675 && y >= 3294 && y <= 3319) || //theiving area
                (x >= 3030 && x <= 3057 && y >= 9756 && y <= 9789) || //mining area #1
                (x >= 3016 && x <= 3059 && y >= 9727 && y <= 9756) || //mining area #2
                (x >= 2700 && x <= 2722 && y >= 3422 && y <= 3445) || //Firemaking/woodcutting area
                (x >= 3185 && x <= 3190 && y >= 3420 && y <= 3427) || //smithing area
                (x >= 2920 && x <= 2931 && y >= 3477 && y <= 3491) || //herblore area
                (x >= 2815 && x <= 2818 && y >= 3439 && y <= 3444) || //cooking area
                (x >= 2835 && x <= 2877 && y >= 3532 && y <= 3557) || //warriors guild
                (x >= 2436 && x <= 2495 && y >= 10122 && y <= 10172) || //black dragon lair
                (x >= 2679 && x <= 2753 && y >= 9427 && y <= 9496) || //steel/mith drag lair
                (x >= 1876 && x <= 1913 && y >= 4355 && y <= 4417) || //green drags lair
                (x >= 1887 && x <= 1934 && y >= 4366 && y <= 4440) || //gold chamber??
                (x >= 2742 && x <= 2785 && y >= 2742 && y <= 3519) || //hydros castle
                (x >= 3135 && x <= 3192 && y >= 3652 && y <= 3702) ||
                (x >= 3179 && x <= 3194 && y >= 3432 && y <= 3446) ||
                (x >= 3250 && x <= 3257 && y >= 3416 && y <= 3423) ||
                (x >= 2943 && x <= 2947 && y >= 2946 && y <= 3373) ||
                (x >= 2943 && x <= 2949 && y >= 3368 && y <= 3368) ||
                (x >= 3009 && x <= 3018 && y >= 3353 && y <= 3358) ||
                (x >= 3009 && x <= 3022 && y >= 3353 && y <= 3356) ||
                (x >= 2721 && x <= 2730 && y >= 3490 && y <= 3503) ||
                (x >= 2724 && x <= 2727 && y >= 3487 && y <= 3489) ||
                (x >= 2649 && x <= 2658 && y >= 3280 && y <= 3287) ||
                (x >= 2612 && x <= 2621 && y >= 3330 && y <= 3335) ||
                (x >= 3201 && x <= 3229 && y >= 3217 && y <= 3220) ||
                (x >= 3201 && x <= 3226 && y >= 3209 && y <= 3228) ||
                (x >= 3201 && x <= 3225 && y >= 3208 && y <= 3229) ||
                (x >= 3201 && x <= 3224 && y >= 3207 && y <= 3230) ||
                (x >= 3201 && x <= 3223 && y >= 3206 && y <= 3231) ||
                (x >= 3201 && x <= 3222 && y >= 3205 && y <= 3232) ||
                (x >= 3201 && x <= 3221 && y >= 3204 && y <= 3233) ||
                (x >= 3201 && x <= 3220 && y >= 3203 && y <= 3234) ||
                (x >= 3201 && x <= 3213 && y >= 3202 && y <= 3235) ||
                (x >= 3201 && x <= 3212 && y >= 3201 && y <= 3236) ||
                (x >= 3201 && x <= 3203 && y >= 3202 && y <= 3235) ||
                (x >= 3201 && x <= 3202 && y >= 3203 && y <= 3234) ||
                (x >= 3264 && x <= 3279 && y >= 3672 && y <= 3695) ||
                (x >= 3021 && x <= 3071 && y >= 9563 && y <= 9601) || //off limits
                (x >= 3021 && x <= 3072 && y >= 9539 && y <= 9560) || //saradomin lair
                (x >= 2433 && x <= 2495 && y >= 5252 && y <= 5310) || // FB
                //(x >= 2811 && x <= 2947 && y >= 0000 && y <= 5365) || //GWD
                (x >= 3148 && x <= 3179 && y >= 3472 && y <= 3504) || // GE
                (x >= 2968 && x <= 3000 && y >= 4367 && y <= 4401) || // CORP
                (x >= 3459 && x <= 3515 && y >= 9481 && y <= 9523) || // KALPHITE LAIR
                (x >= 3447 && x <= 3529 && y >= 9466 && y <= 9537) || // KALPHITE LAIR
                (x >= 2242 && x <= 2298 && y >= 4667 && y <= 4722) || // KBD
                (x >= 3133 && x <= 3135 && y >= 3634 && y <= 3636) || // Stealing creations [portal]
                (x >= 3140 && x <= 3145 && y >= 3633 && y <= 3638) || // Stealing creations [house east]
                (x >= 3122 && x <= 3129 && y >= 3635 && y <= 3638) || // Stealing creations [house west]
                (x >= 3039 && x <= 3161 && y >= 3428 && y <= 3523) || // EDGEVILLE
                (x >= 3520 && x <= 3585 && y >= 9659 && y <= 9725) || // BARROWS
                (x >= 2820 && x <= 2880 && y >= 5249 && y <= 5308) || // ARMADYL GW
                (x >= 2816 && x <= 2889 && y >= 5309 && y <= 5375) || // BANDOS GW
                (x >= 2881 && x <= 2933 && y >= 5256 && y <= 5380) || // SARADOMIN GW
                (x >= 2878 && x <= 2948 && y >= 5320 && y <= 5360) || // ZAMORAK GW
                (x >= 2833 && x <= 2856 && y >= 4819 && y <= 4846) || // Runecrafting altars
                (x >= 2811 && x <= 2894 && y >= 2940 && y <= 3026) || // Shilo
                (x >= 2950 && x <= 2955 && y >= 3658 && y <= 3666) || // Pkbox
                (x >= 2454 && x <= 2469 && y >= 5281 && y <= 5297) || // Flambeed
                (x >= 2639 && x <= 2675 && y >= 2579 && y <= 2625) || // PC
	(x >= 1968 && x <= 1979 && y >= 4904 && y <= 4920) || // Tormented Demons
                (x >= 2441 && x <= 2646 && y >= 2817 && y <= 3883) || // staffzone
		(x >= 1970 && x <= 1977 && y >= 4996 && y <= 5008) || // helpdesk
	(x >= 2841 && x <= 2834 && y >= 10204 && y <= 10215) || // Keldagrim
                (x >= 2117 && x <= 2166 && y >= 4807 && y <= 4857) || // Cosmic Altar
                (x >= 2432 && x <= 2364 && y >= 5199 && y <= 5123) || // jad
                (x >= 1918 && x <= 1853 && y >= 5379 && y <= 5436) || // Seaqueen
                (x >= 2550 && x <= 2528 && y >= 4705 && y <= 4727) || // mage bank(rm1)
                (x >= 2552 && x <= 2488 && y >= 4731 && y <= 4676) || // mage bank(rm2)
                (x >= 1670 && x <= 1727 && y >= 5595 && y <= 5611) || // fog
                (x >= 2905 && x <= 2918 && y >= 5465 && y <= 5478) || // START
                (x >= 2286 && x <= 2377 && y >= 3655 && y <= 3712) || // fishing colony
                (x >= 2646 && x <= 2712 && y >= 3690 && y <= 3736) || // Rock Crabs
                (x >= 2712 && x <= 2646 && y >= 3736 && y <= 3690) || // Rock Crabs
                (x >= 3396 && x <= 3456 && y >= 3529 && y <= 3590) || // Slay
                (x >= 3456 && x <= 3396 && y >= 3590 && y <= 3529) || // Slay
                (x >= 3402 && x <= 3457 && y >= 3592 && y <= 3523) || // Slay
                (x >= 3457 && x <= 3402 && y >= 3523 && y <= 3592) || // Slay
                (x >= 3133 && x <= 3097 && y >= 9867 && y <= 9813) || // Chaos
                (x >= 3097 && x <= 3133 && y >= 9813 && y <= 9867) || // Chaos
                (x >= 3135 && x <= 3086 && y >= 9819 && y <= 9869) || // Chaos
                (x >= 3086 && x <= 3135 && y >= 9869 && y <= 9813) || // Chaos
                (x >= 1595 && x <= 1675 && y >= 5623 && y <= 5580) || // barrelchest
                (x >= 1675 && x <= 1595 && y >= 5580 && y <= 5623) || // barrelchest
                (x >= 1601 && x <= 1666 && y >= 5585 && y <= 5625) || // barrelchest
                (x >= 1666 && x <= 1601 && y >= 5625 && y <= 5585) || // barrelchest
                (x >= 3018 && x <= 3058 && y >= 4818 && y <= 4849) || //runecrafting-abyss
                (x >= 2247 && x <= 2297 && y >= 4825 && y <= 4860) || //runecrafting-Chaos
                (x >= 2442 && x <= 2483 && y >= 4806 && y <= 4853) || //runecrafting-Law
                (x >= 2184 && x <= 2230 && y >= 4817 && y <= 4860) || //runecrafting-Death
                (x >= 3469 && x <= 3500 && y >= 4819 && y <= 4847) || //runecrafting-Water
                //(x >= 3135 && x <= 3192 && y >= 3652 && y <= 3702) || //runecrafting-Soul(not working)
                (x >= 2761 && x <= 2807 && y >= 4816 && y <= 4857) || //runecrafting-mind
                (x >= 2503 && x <= 2540 && y >= 4827 && y <= 4854) || //runecrafting-body
                (x >= 2567 && x <= 2600 && y >= 4822 && y <= 4852) || //runecrafting-Fire
                (x >= 2630 && x <= 2687 && y >= 4816 && y <= 4858) || //runecrafting-Earth
                (x >= 2136 && x <= 2166 && y >= 4827 && y <= 4836) || //runecrafting-Cosmic
                (x >= 2390 && x <= 2409 && y >= 4829 && y <= 4850) || //runecrafting-Nature
                (x >= 3201 && x <= 3201 && y >= 3204 && y <= 3233)) {
            /*if ((attacking == null && attackedBy == null) || (timerStarted && System.currentTimeMillis()
                    - PVPTimer >= 100000)) {
                if (timerStarted) {
                    removeWilderness();
                    timerStarted = false;
                }
                return false;
            } else if (!timerStarted && (attacking == null || attackedBy != null)) {
                PVPTimer = System.currentTimeMillis();
                timerStarted = true;
            }*/
            if (!removedWildy) {
                removeWilderness();
                removedWildy = true;
            }
            return false;

        }
        return true;
    }

    public int getWildernessLevel() {
        int level = 0;
        if (absY >= 3525 && absY <= 3527) {
            level = 1;
        } else if (absY >= 3526 && absY <= 3535) {
            level = 2;
        } else {
            level = 3 + (int) Math.ceil((absY - 3536) / 8);
        }
        if (level < 0 || absY < 3525) {
            level = 0;
        }
        if (!isPVP()) {
            return level;
        }
        if (isPVP()) {
            double base = 5 + (combatLevel * 0.10);
            int total = (int) Math.round(base) + level;
            if (wildernessZone(absX, absY)) {
                return total;
            } else {
                return 0;
            }
        }
        return level;
    }

    public boolean properWildernessLevel(int thisCombat, int opponentCombat) {
        int difference = thisCombat >= opponentCombat ? thisCombat - opponentCombat : opponentCombat - thisCombat;
        return getWildernessLevel() >= difference;
    }
		public void loadInterfaces()
	{
	getActionSender().setString(this,"Tele's Quests & Info",274,2);
	getActionSender().setString(this,"Teleports:",274,11);
	getActionSender().setString(this,"Home",274,12);
	getActionSender().setString(this,"Sea",274,13);
	getActionSender().setString(this,"Train",274,14);
	getActionSender().setString(this,"Jad",274,15);
	getActionSender().setString(this,"Barrelchest",274,16);
	getActionSender().setString(this,"Chaos",274,17);
	getActionSender().setString(this,"Abyss",274,18);
	getActionSender().setString(this,"Bounty Hunter",274,19);
	getActionSender().setString(this,"Agility",274,20);
	getActionSender().setString(this,"Bandos",274,21);
	getActionSender().setString(this,"Zamorak",274,22);
	getActionSender().setString(this,"Armadyl",274,23);
	getActionSender().setString(this,"Saradomin",274,24);
	getActionSender().setString(this,"Pest Control",274,25);
	getActionSender().setString(this,"Flambeed",274,26);
	getActionSender().setString(this,"Tormented Demons",274,27);
	getActionSender().setString(this,"Barrows",274,28);
	getActionSender().setString(this,"Dark Beasts",274,29);
	getActionSender().setString(this,"Corporeal Beast",274,30);
	getActionSender().setString(this,"Kalphite Queen",274,31);
	getActionSender().setString(this,"King Black Dragon",274,32);
	getActionSender().setString(this,"Pkbox(unsafe)",274,33);
	getActionSender().setString(this,"Chillzone",274,34);
	getActionSender().setString(this,"Pvp(unsafe)",274,35);
	getActionSender().setString(this,"Pvp1(unsafe)",274,36);
	getActionSender().setString(this,"Pvp2(unsafe)",274,37);
	getActionSender().setString(this,"Pvp3(unsafe)",274,38);
	getActionSender().setString(this,"Pvp4(unsafe)",274,39);
	getActionSender().setString(this,"Fun Pvp(safe)",274,40);
	getActionSender().setString(this,"INFORMATION:",274,41);
	getActionSender().setString(this, "<col=33FF00>Players online: <col=33FF00>"+Engine.getPlayerCount(), 274, 42);
	getActionSender().setString(this, "<col=33FF00>Pk Points", 274, 43);
	getActionSender().setString(this, "<col=33FF00>Death Count", 274, 44);
	getActionSender().setString(this, "<col=33FF00>Extra Potential", 274, 45);
	getActionSender().setString(this,"QUESTS:",274,46);
	getActionSender().setString(this,"Awakening a Nightmare",274,48);
	getActionSender().setString(this,"<col=FFFF00>Awakening a Nightmare",274,48);
	getActionSender().setString(this,"<col=33FF00>Awakening a Nightmare",274,48);
	getActionSender().setString(this,"",274,49);
	getActionSender().setString(this,"",274,50);
	getActionSender().setString(this,"",274,51);
	}
		
	public void clearInterface(int interfaceId, int amount)
	{
	for(int i = 0; i < amount; i++) {
	getActionSender().setString(this,"",interfaceId,i);
	}
	}
	
	public void writeInterface(int interfaceId, int amount)
	{
	for(int i = 0; i < amount; i++) {
	getActionSender().setString(this,""+i+"",interfaceId,i);
	}
	}

    public void restoreTabs(Player p) {
        for (int b = 16; b <= 21; b++) {
            p.actionSender.setInterfaceConfig(p, 548, b, false);
        }

        for (int a = 32; a <= 38; a++) {
            p.actionSender.setInterfaceConfig(p, 548, a, false);
        }
        p.calculateEquipmentBonus();

        p.actionSender.setInterfaceConfig(p, 548, 14, false);
        p.actionSender.setInterfaceConfig(p, 548, 31, false);
        p.actionSender.setInterfaceConfig(p, 548, 63, false);

        p.actionSender.setInterfaceConfig(p, 548, 72, false);
    }

    public void hideTabs(Player p) {
        for (int b = 16; b <= 21; b++) {
            p.actionSender.setInterfaceConfig(p, 548, b, true);
        }

        for (int a = 32; a <= 38; a++) {
            p.actionSender.setInterfaceConfig(p, 548, a, true);
        }
        p.calculateEquipmentBonus();

        p.actionSender.setInterfaceConfig(p, 548, 14, true);
        p.actionSender.setInterfaceConfig(p, 548, 31, true);
        p.actionSender.setInterfaceConfig(p, 548, 63, true);

        p.actionSender.setInterfaceConfig(p, 548, 72, true);
    }

    /**
     * Wilderness level
     */
    public int wildLevel;
    /**
     * If player updated the Wilderness level.
     */
    public boolean updatedLevel;
    public int savedLevel;
    /**
     * Thieving.
     */
    public int[] thievingArray = new int[4];
    public int maxArrays = 10;
    public boolean[] optionArray = new boolean[maxArrays];
    public Startup startup = new Startup(this);
    /**
     * Quest variables
     */
    public int questId;
    public int questStage;
    public QuestDevelopment quest = new QuestDevelopment(this);
    /**
     * Has entered defence room Warrior guild.
     */
    public boolean enteredDefenceRoom;
    /**
     * Prevents XLogging.
     */
    public int combatType;
    /**
     * The delay for making a fire.
     */
    public int[] firemaking = new int[4];
    /**
     * Next graphic creating delay for MSB Special attack
     */
    public int nextDamageDelay = -1;
    public int nextGraphicDelay = -1;

    public static int Dropparty[] = {4219, 9185, 8839, 8840, 8841, 11663, 11664, 11665, 1305, 1149, 1215, 1540, 1434, 1377, 1645, 1911, 3140, 4087, 3204, 3176, 4587, 5680, 6739, 7158, 7461, 11283, 4151, 11732, 11335, 1038, 1040, 1042, 1044, 1046, 1048};

    public static int RandomItemsDropparty() {
        return Dropparty[(int) (Math.random() * Dropparty.length)];
    }

    public static int Dropparty2[] = {11283, 4151, 11732, 11335, 1038, 1040, 1042, 1044, 1046, 1048};

    public static int RandomItemsDropparty2() {
        return Dropparty2[(int) (Math.random() * Dropparty2.length)];
    }

    /**
     * Option variable
     */
    public int optionId;
    /**
     * Defender dropping types variable
     */
    public int defenderId;

    /**
     * Wilderness Levels
     */
    public int wildernessLevel;


    /**
     * Summoning variables
     */
    public int summonTeleDelay = -1;
    public int summonDrainDelay = -1;
    public boolean callFamiliar;
    public boolean familiarDissMiss;
    public boolean summonedFamiliar;

    /**
     * Warrior Guild variables
     */
    public int[] randomItemIds = {
            8843, 8844, 8845, 8846, 8847, 8848, 8849, 8850
    };
    public String warriorArmour;

    /**
     * autoCast Variables
     */
    public int[] regularStaffs = {
            1381
    };
    public int[] otherStaffs = {
            4675
    };
    public int autoCastDmgDelay = -1;
    public int autoCastDelay;
    public int[] autoCast = new int[3];
    public boolean castAuto;
    public int autoCastSpellbook = 192; // Default: Moderns
    public long lastAutoCast = 0;
    public boolean usingAutoCast;
    /**
     * If player is disturbing commander zilyana.
     */
    public boolean disturbSara;
    /**
     * Death Delays
     */
    public int deathEmoteDelay = -1;
    /**
     * Yell delay
     */
    public int bhTarget = 0;
    public int penalty = 0;
    public boolean cantLeave = false;
    public boolean inBounty = false;
    public int massYellDelay = 0;

    /**
     * Crystal bow shots.
     */
    public int crystalShots;

    /**
     * Wilderness ditch jump data.
     */
    public int jumpDelay = 0;
    public boolean jumpUpdateReq = false;

    public int equipSpecDelay;
    public int[] miningAxes = {
            1265, 1267, 1269, 1271, 1273, 1275
    };
    public boolean isBanking;

    /**
     * Dueling variables
     */
    public int countDelay = -1;
    public int countType = -1;
    public boolean duelDeath;
    public boolean acceptDuel;
    public boolean acceptScreen1, acceptScreen2;
    public int duelFriend;
    public boolean duelScreen1, duelScreen2;

    public int explodeType;
    public int explodeDelay = -1;

    public int[] godWarsKills = new int[5];

    public int watchId = -1;

    public int spellType;

    public int playerStart;

    public boolean muteExpect, muteExpect2;
    public int muteType;
    public int[] hugeNpcs = {
            50, 1155, 1157, 1158, 1160, 2745, 6222, 6203, 8133, 7134, 7133
			};

    /**
     * Woodcutting variables
     */
    public int cutDelay;
    public boolean isWoodcutting;

    /**
     * Dueling variables
     */
    public boolean isBusy;
    public int duelEnemy;
    public boolean inDuelFight;

    /**
     * Pet variables
     */
    public int petKeeper;
    public boolean summonedPet;

    /**
     * Mage Arena variables
     */
    public int kolodionDelay;
    public boolean arenaActive;

    /**
     * Slayer variables
     */
    public int slayerAmount1;
    public int slayerType1;
    public int[] slayerType = {
            1615, 5363, 55, 54
    };
    public boolean slayerTask;
    public int[] slayerArray = {
            1, 2, 3, 4
    };
    public int slayerAmount;

    /**
     * Pvn variables
     */
    public int damageSpecDelay = -1;
    public boolean enableSpecDamage;
    public int damageDelay1 = -1;
    public boolean enableDamage;
    public int atkDelay;
    public boolean attackingNpc;
    public int attackNpc;


    /**
     * Thieving variables.
     */
    public int pickPocketDelay;

    /**
     * This variable is added to add facing if player is gonna pickpocket.
     */
    public int npcClick2;

    /**
     * Mining variables.
     */
    public int rockId;
    public boolean isMining;
    public int receiveOreDelay;
    public int miningDelay;

    /**
     * Wilderness variables.
     */
    public int wildyLevel;

    public int statDelay = 100; //Stat update delay
    public int hpDelay = 100; //HP update delay

    /**
     * Emote clicking delay.
     */
    public int animClickDelay;

    public boolean usingPrayer;
    public int buryDelay;
    public int drainDelay;
    public boolean rangedPrayer;
    public boolean meleePrayer;
    public boolean magicPrayer;
    public boolean retriPrayer;
    public boolean redempPrayer;

    //Prayer

    public double[][] prayers = {{1, 0, 5}, {4, 0, 5}, {7, 0, 5}, {8, 0, 5}, {9, 0, 5}, {10, 0, 10}, {13, 0, 10}, {16, 0, 10}, {19, 0, 1.67}, {22, 0, 3.33}, {25, 0, 3.33}, {26, 0, 10}, {27, 0, 10}, {28, 0, 20}, {31, 0, 20}, {34, 0, 20}, {36, 0, 20}, {37, 0, 20}, {40, 0, 20}, {43, 0, 20}, {44, 0, 20}, {45, 0, 20}, {46, 0, 5}, {49, 0, 10}, {52, 0, 30}, {60, 0, 38.33}, {70, 0, 38.33}};
    public int headIconPrayer = -1;
    public double drainCount = 0;

    public boolean canPray(int prayer) {
        if (skillLvl[5] > 0 && getLevelForXP(5) >= prayers[prayer][0]) {
            return true;
        }
        return false;
    }

    public boolean usingPrayer(String prayer) {
        if (prayer.equals("protectmage")) { //Protect from Magic
            return usingPrayer(17);
        } else if (prayer.equals("protectrange")) { // Protect from Missiles (Range)
            return usingPrayer(18);
        } else if (prayer.equals("protectmelee")) {
            return usingPrayer(19);
        }
        return false;
    }

    public boolean usingPrayer(int prayer) {
        return prayers[prayer][1] == 1;
    }

    public boolean usingPrayer() {
        int i = 0;
        while (i <= 26) {
            if (prayers[i][1] == 1) return true;
            i++;
        }
        return false;
    }

    public void sendTname() {
        Player p3 = Engine.players[this.bhTarget];
        if (p3 != null) {
            actionSender.sendMessage(this, "Your target name is " + p3.username + ".");
        } else {
            actionSender.sendMessage(this, "You do not have a target yet, still searching..");
        }
    }

    public void targOverlay() {
        Player p3 = Engine.players[this.bhTarget];
        if (p3 != null) {
            this.actionSender.setOverlay(this, 653);
            this.actionSender.setString(this, " " + p3.username + " ", 653, 8);
            tOverlay = true;
            tOverlay1 = true;
        }
    }

    /*public void Addwhat() {
         if (combatLevel >= 116 && !beeninwild)  {
             actionSender.sendMessage(this, "Added "+this.username+" to the list of possible targets in the range of 116+ combat.");
             BhTarg.Targs.add(this.playerId);
         } else if (combatLevel >= 100 && combatLevel <= 115 && !beeninwild) {
             actionSender.sendMessage(this, "Added "+this.username+" to the list of possible targets in the range of 100 - 115 combat.");
             BhTarg.Targs1.add(this.playerId);
         } else if (combatLevel >= 85 && combatLevel <= 99 && !beeninwild) {
             actionSender.sendMessage(this, "Added "+this.username+" to the list of possible targets in the range of 85 - 99 combat.");
             BhTarg.Targs2.add(this.playerId);
         } else if (combatLevel >= 70 && combatLevel <= 84 && !beeninwild) {
             actionSender.sendMessage(this, "Added "+this.username+" to the list of possible targets in the range of 70 - 84 combat.");
             BhTarg.Targs3.add(this.playerId);
         } else if (combatLevel >= 55 && combatLevel <= 69 && !beeninwild) {
             actionSender.sendMessage(this, "Added "+this.username+" to the list of possible targets in the range of 55 - 69 combat.");
             BhTarg.Targs4.add(this.playerId);
         } else if (combatLevel <= 54 && !beeninwild) {
             actionSender.sendMessage(this, "Added "+this.username+" to the list of possible targets in the range of 54- combat.");
             BhTarg.Targs5.add(this.playerId);
         }
     }*/

    /*public void removewhat() {
         if (combatLevel > 116) {
             BhTarg.Targs.remove(this.playerId);
         } else if (combatLevel > 100 && combatLevel < 115) {
             BhTarg.Targs1.remove(this.playerId);
         } else if (combatLevel > 85 && combatLevel < 100) {
             BhTarg.Targs2.remove(this.playerId);
         } else if (combatLevel > 70 && combatLevel < 85) {
             BhTarg.Targs3.remove(this.playerId);
         } else if (combatLevel > 55 && combatLevel < 70) {
             BhTarg.Targs4.remove(this.playerId);
         }
     }*/
    /*public void Targwho() {
          if (combatLevel > 116 && !beeninwild && targetTime == 0) {
             this.bhTarget = BhTarg.testGet(this);
             needsarrow = true;
             actionSender.sendMessage(this, "Attempting to acquire a target for "+this.username+" in the range of 116+ combat.");
             sendTname();
             targOverlay();
         } else if (combatLevel > 100 && combatLevel <= 115 && !beeninwild && targetTime == 0) {
                 this.bhTarget = BhTarg.testGet1(this);
             sendTname();
             actionSender.sendMessage(this, "Attempting to acquire a target for "+this.username+" in the range of 100 - 115 combat.");
             targOverlay();
         } else if (combatLevel > 85 && combatLevel <= 100 && !beeninwild && targetTime == 0) {
                 this.bhTarget = BhTarg.testGet2(this);
             actionSender.sendMessage(this, "Attempting to acquire a target for "+this.username+" in the range of 85 - 99 combat.");
             sendTname();
             targOverlay();
         } else if (combatLevel > 70 && combatLevel <= 85 && !beeninwild && targetTime == 0) {
                 this.bhTarget = BhTarg.testGet3(this);
             actionSender.sendMessage(this, "Attempting to acquire a target for "+this.username+" in the range of 70 - 84 combat.");
             sendTname();
             targOverlay();
         } else if (combatLevel > 55 && combatLevel <= 69 && !beeninwild && targetTime == 0) {
                 this.bhTarget = BhTarg.testGet4(this);
             actionSender.sendMessage(this, "Attempting to acquire a target for "+this.username+" in the range of 55 - 69 combat.");
             sendTname();
             targOverlay();
         }
     }*/
    /*public void Targwho1() {
          if (combatLevel > 116 && !beeninwild) {
             BhTarg.getTarget(this);
         } else if (combatLevel > 100 && combatLevel <= 115 && !beeninwild) {
             BhTarg.getTarget1(this);
         } else if (combatLevel > 85 && combatLevel <= 100 && !beeninwild) {
             BhTarg.getTarget2(this);
         } else if (combatLevel > 70 && combatLevel <= 85 && !beeninwild) {
             BhTarg.getTarget3(this);
         } else if (combatLevel > 55 && combatLevel <= 69 && !beeninwild) {
             BhTarg.getTarget4(this);
         }
     }*/

    public void togglePrayer(int prayer, int toggle) {
        int[] configuration = {83, 84, 85, 862, 863, 86, 87, 88, 89, 90, 91, 864, 865, 92, 93, 94, 1168, 95, 96, 97, 866, 867, 98, 99, 100, 1052, 1053};
        prayers[prayer][1] = toggle;
        actionSender.setConfig(this, configuration[prayer], toggle);
    }

    public double prayerDrain() {
        int i = 0;
        double drainPerMinute = 0;
        while (i <= 26) {
            if (usingPrayer(i)) drainPerMinute += prayers[i][2];
            i++;
        }
        drainPerMinute *= 1 + (equipmentBonus[11] / 30);
        return drainPerMinute / 100;
    }

    public void switchPrayers(int[] prayers, int prayer) {
        if (!canPray(prayer)) {
            return;
        }
        for (int i : prayers) {
            if (usingPrayer(i)) {
                togglePrayer(i, 0);
            }
        }
    }

    public void prayerSounds(int prayer) {
        int sound = 0;
        switch (prayer) {
            case 0:
                sound = 2690;
                break;
            case 1:
                sound = 2688;
                break;
            case 2:
                sound = 2664;
                break;
            case 3:
                sound = 2685;
                break;
            case 4:
                sound = 2668;
                break;
            case 5:
                sound = 2684;
                break;
            case 6:
                sound = 2689;
                break;
            case 7:
                sound = 2662;
                break;
            case 8:
                sound = 2679;
                break;
            case 9:
                sound = 2678;
                break;
            case 10:
                sound = 0;
                break;
            case 11:
                sound = 2666;
                break;
            case 12:
                sound = 2670;
                break;
            case 13:
                sound = 2687;
                break;
            case 14:
                sound = 2691;
                break;
            case 15:
                sound = 2667;
                break;
            case 16:
                sound = 0;
                break;
            case 17:
                sound = 2675;
                break;
            case 18:
                sound = 2677;
                break;
            case 19:
                sound = 2676;
                break;
            case 20:
                sound = 2665;
                break;
            case 21:
                sound = 2669;
                break;
            case 22:
                sound = 2682;
                break;
            case 23:
                sound = 2680;
                break;
            case 24:
                sound = 2686;
                break;
            case 25:
                sound = 3826;
                break;
            case 26:
                sound = 3825;
                break;
        }
        if (sound != 0) {
            actionSender.addSoundEffect(this, sound, 1, 0, 0);
        }
    }

    public void resetPrayer() {
        int i = 0;
        while (i <= 26) {
            togglePrayer(i, 0);
            i++;
        }
        drainCount = 0;
        headIconPrayer = -1;
        updateReq = true;
        appearanceUpdateReq = true;
    }


    /**
     * Magic combat variables
     */
    public int freezeDelay;
    public int vengeanceDelay;
    public boolean vengeance;
    public int spellbookSwapTimer;
    public boolean spellbookSwap;
    public boolean usedSpellbookSwap;
    public int mageDelay;

    /**
     * Agility Variables
     */
    public int[] agilityX = {
            2476, 2475, 2474, 2473, 2472, 2471
    };
    public int[] agilityY = {
            3426
    };
    public boolean agilityPerforming;
    public int agilityDelay;
    public int agilityType;

    /**
     * Combat variables
     */
    public int antifire;
    public boolean fadeAway;
    public int enemyFadeAwayDelay = -1;
    public int fightStyle = 1;
    public int[] strangeItems = {
            6570
    };
    public int battleCDelay;
    public int battleCount;
    public int poisonDelay;
    public int poisonHitCount;
    public boolean isPoisoned;
    public int headIconSkull = -1;
    public boolean isSkulled;
    public int skullVanishDelay;
    public int rangeDmgDelay = -1;
    public int rangeDmgDelay2 = -1;

    public int[] rangeBows = {
            841, 843, 845, 847, 849, 851, 853,
            855, 857, 859, 861, 9174, 9176, 9177,
            9179, 9181, 9183, 9185
    };
    public int[] rangeArrows = {
            882, 884, 886, 888, 890, 892
    };
    public int[] godSwords = {
            11694, 11696, 11698, 11700
    };
    public int myBonus;
    public int meleeDef;
    public int waitDeathDelay = -1;
    public boolean randomVariable;
    public int deathDelay = -1;
    public boolean isDead;
    public boolean inCombat = false;                            
    public int SummonDelay = 0;
    public int specDelay = -1;
    public int secondSpecDelay = -1;
    public int thirdSpecDelay = -1;	
    public int fourthSpecDelay = -1; 
    public int delayedDamageDelay = -1;
    public int delayedDamageHit = -1;
    public boolean expectSpec;
    public boolean autoRetaliate = true;
    public int specFillDelay = 50;
    public boolean usingSpecial;
    public int specAmount;
    public int damageDelay;
    public boolean damagePending;
    public int combatDelay;
    public int enemyIndex;
    public boolean attackingPlayer;
    public int procast = 0;
    public PlayerMagic playerMagic = new PlayerMagic(this);
    /**
     * Player's index.
     */
    public int playerId = 0;
    /**
     * Class for storing and converting bytes.
     */
    public ByteVector stream = new ByteVector(500, 5000);
    /**
     * Player's socket for handling most io operations.
     */
    public PlayerSocket socket;
    /**
     * Set to true if the player has finished the login stage.
     */
    public boolean online = false;
    /**
     * Player's username.
     */
    public String username = "null"; // Name
    public String username2 = "null"; // Name with capital letter first
    /**
     * Donor (Members)
     */
     
    public boolean donor = false;

    public boolean donor() {
        if (rights > 0) {
            donor = true;
            return true;
        } else {
            return donor;
        }
    }
    /**
     * Player's password.
     */
    public String password = "";
    /**
     * Player's rights.
     */
    public int rights = 0;
    /**
     * Player's starter.
     */
    public int talk = 0;
    public int talked = 0;
    public int starter = 0;
    /**
     * 1 set to true means socket disconnected but logged in, both for removing the player.
     */
    public boolean[] disconnected = new boolean[2];
    /**
     * The region this player is in.
     */
    public int mapRegionX = 0;
    public int mapRegionY = 0;
    /**
     * The position this player is at in the map region.
     */
    public int currentX = 0;
    public int currentY = 0;
    /**
     * Absolute coordinates this player is at.
     */
    public int absX = 0;
    public int absY = 0;
    /**
     * New player
     */
    public boolean newPlayer = true;
    /**
     * The height level this player is at.
     */
    public int heightLevel = 0;
    public int tempHeight = 0;
    public int tempHeight2 = 0;
    /**
     * Storing players spellbook
     */
    public int spellbook = 192;
    /**
     * If either are above -1 then the player is in motion.
     */
    public int walkDir = -1;
    public int runDir = -1;
    /**
     * True if the player is running, false if it isn't.
     */
    public boolean isRunning = false;
    /**
     * Set to true if the player has entered a new map region.
     */
    public boolean mapRegionDidChange = false;
    /**
     * Set to true if teleported.
     */
    public boolean didTeleport = false;
    /**
     * Set Absolute coordinates to these.
     */
    public int teleportToX = -1;
    public int teleportToY = -1;
    /**
     * True if the player is Reqing an update.
     */
    public boolean updateReq = false;
    /**
     * Max number of steps this player can have pending.
     */
    public int walkingQueueSize = 50;
    public int wQueueReadPtr = 0;
    public int wQueueWritePtr = 0;
    /**
     * Positions the player is Reqing to walk to.
     */
    public int[] walkingQueueX = new int[walkingQueueSize];
    public int[] walkingQueueY = new int[walkingQueueSize];
    public int[] walkingQueue = new int[walkingQueueSize];
    /**
     * All the players within distance.
     */
    public Player[] playerList = new Player[Engine.players.length];
    /**
     * All the players stored in distance.
     */
    public byte[] playersInList = new byte[Engine.players.length];
    public int playerListSize = 0;
    /**
     * True if chatting is Reqing to be sent.
     */
    public boolean chatTextUpdateReq = false;
    public String chatText = "";
    public int chatTextEffects = 0;
    /**
     * True if an appearance update is needed.
     */
    public boolean appearanceUpdateReq = false;
    /**
     * Animation data.
     */
    public boolean animUpdateReq = false;
    public int animReq = -1;
    public int animDelay = 0;
    /**
     * GFX data.
     */
    public boolean gfxUpdateReq = false;
    public int gfxReq = -1;
    public int gfxDelay = 0;
    /**
     * Player and NPC facing data.
     */
    public boolean faceToUpdateReq = false;
    public int faceToReq = -1;
    /**
     * Damage data.
     */
    public boolean hit1UpdateReq = false;
    public boolean hit2UpdateReq = false;
    public int hitDiff1 = 0;
    public int hitDiff2 = 0;
    public int poisonHit1 = 0;
    public int poisonHit2 = 0;
    /**
     * Skill level data.
     */
    public int[] skillLvl = new int[25];
    public int[] skillXP = new int[25];
    public int combatLevel = 0;
    /**
     * Equipment data.
     */
    public int[] equipment = new int[14];
    public int[] equipmentN = new int[14];
    public int[] equipmentBonus = new int[12];
    /**
     * Player appearance.
     */
    public int[] color = new int[5];
    public int[] look = new int[7];
    public int npcType = -1;
    public int gender = 0;
    /**
     * Shops
     */
    public ShopHandler shopHandler = new ShopHandler(this);
    public Shops shops = new Shops();
    /**
     * Player emotes
     */
    public int runEmote = 0x338;
    public int walkEmote = 0x333;
    public int standEmote = 0x328;
    /**
     * All the NPCs within distance.
     */
    public NPC[] npcList = new NPC[Engine.npcs.length];
    /**
     * All the npcs stored in distance.
     */
    public byte[] npcsInList = new byte[Engine.npcs.length];
    public int npcListSize = 0;
    /**
     * Rebuild the entire NPC list.
     */
    public boolean rebuildNPCList = false;
    /**
     * An array storing all the players items.
     */
    public int[] items = new int[28];
    public int[] itemsN = new int[28];
    public int[] shopItems = new int[40];
    public int[] shopItemsN = new int[40];
    public int[] maxItemAmount = new int[40];

    //public int maxItemAmt = 2147000000;
    /**
     * Open interfaces, use these to confirm an interface is open when trying to use one.
     */
    public int interfaceId = -1;
    public int chatboxInterfaceId = -1;
    /**
     * The current position in the login stage.
     */
    public int loginStage = 0;
    /**
     * Click x position.
     */
    public int clickX = 0;
    /**
     * Click y position.
     */
    public int clickY = 0;
    /**
     * Click id.
     */
    public int clickId = 0;
    /**
     * Eat delay.
     */
    public int eatDelay;
    public int drinkDelay;
    /**
     * True if the player is trying to pickup an item.
     */
    public boolean itemPickup = false;
    /**
     * Set run energy.
     */
    public boolean runEnergyUpdateReq = false;
    /**
     * Amount of current run energy.
     */
    public int runEnergy = 100;
    /**
     * Delay before run energy can increase.
     */
    public int runEnergyDelay = 0;
    /**
     * Clicked the first option on a player.
     */
    public boolean playerOption1 = false;
    /**
     * Clicked the second option on a player.
     */
    public boolean playerOption2 = false;
    /**
     * Clicked the third option on a player.
     */
    public boolean playerOption3 = false;
    /**
     * Clicked the first option on a NPC.
     */
    public boolean npcOption1 = false;
    /**
     * Clicked the first option on an object.
     */
    public boolean objectOption1 = false;
    /**
     * Setting the prayer system effects.
     */
    public PrayerSystem prayerSystem = new PrayerSystem(this);
    /**
     * Setting the players weapon.
     */
    public PlayerWeapon playerWeapon = new PlayerWeapon(this);
    /**
     * Clicked the second option on an object.
     */
    public boolean objectOption2 = false;
    /**
     * Clicked the second option on a NPC.
     */
    public boolean npcOption2 = false;
    /**
     * Forced chat.
     */
    public String forceChat = "";
    public boolean forceChatUpdateReq = false;
    /**
     * Teleporting variables.
     */
    public int teleX = -1;
    public int teleY = -1;
    public int teleH = -1;
    public int teleDelay = -1;
    public int teleFinishGFX = 0;
    public int teleFinishGFXHeight = 0;
    public int teleFinishAnim = 0;
    /**
     * Delay before recieving packets.
     */
    public int clickDelay = -1;
    public long loginTimeout = System.currentTimeMillis();
    public runecrafting runecrafting = new runecrafting();
    public Woodcutting woodcutting;

    /**
     * Constructs a new Player.
     *
     * @param socket The socket this Player belongs to.
     * @param id     The index this player is at.
     */
    public Player(Socket socket, int id) {

        /**
         *  Skills
         */
        this.woodcutting = new Woodcutting(this);

        this.socket = new PlayerSocket(this, socket);
        playerId = id;
        look[1] = 10;
        look[2] = 18;
        look[3] = 26;
        look[4] = 33;
        look[5] = 36;
        look[6] = 42;
        for (int i = 0; i < skillLvl.length; i++) {
            skillLvl[5] = 1;
            skillXP[5] = 0;
            skillLvl[6] = 1;
            skillXP[6] = 0;
            skillLvl[3] = 10;
            skillXP[3] = 1545;
            skillLvl[i] = 1;
            skillXP[i] = 0;
        }
        for (int i = 0; i < items.length; i++) {
            items[i] = -1;
        }
        for (int i = 0; i < equipment.length; i++) {
            equipment[i] = -1;
        }
        for (int i = 0; i < bankItems.length; i++) {
            bankItems[i] = -1;
        }
        pTrade = new PTrade(this);

        //Shops
        for (int i = 0; i < 40; i++) {
            shopItems[i] = -1;
        }
        shopItems = shopItems;
        shopItemsN = shopItemsN;
        maxItemAmount = shopItemsN;
    }

    public boolean skillCapeEquipped() {
        for (int i = 10639; i < 10663; i++) {
            for (int j = 9747; j < 9812; j++) {
                if (equipment[1] == i || equipment[1] == j || equipment[1] == 12169 || equipment[1] == 12170) {
                    return true;
                }
            }
        }
        return false;
    }

    public int logoutTimer;
    public int restoreSpecialTimer;

    public void Procast() {
        Player opp = Server.engine.players[this.magicOppIndex];
        if (this.procast == 0) {
            this.playerMagic.combatMagic(opp, 193, 3);
            this.procast = 3;
        }
    }


    public void processTimers() { //Processes evenly at 1000 milliseconds

        Player p3 = Engine.players[this.target];
        //this.targetname = "...";
	if (cookTimer > 0) {
		cookTimer--;
	}
	if (cookTimer == 0) {
	    if (cookAmount == 0) {
		cookTimer = -1;
	    } else {
		Cook(this, cookXP, cookID, cookGet, cookName);
	    }
	}
        if (targetTime > 0) {
            targetTime--;
        }
        if (ServerMess > 0) {
            ServerMess--;
        }
        if (ServerMess == 1) {
                    int randomInt = Misc.random(8);
                    switch (randomInt) {
                    case 1:
                    case 5:
                    case 6:
                    	this.actionSender.sendMessage(this, "Thank you for staying here at Rune-Resort!");
                    	ServerMess = 61;
                    	break;
                    case 2:
                    case 7:
                    	this.actionSender.sendMessage(this, "We would appreciate it if you'd join the forums!");
                    	this.actionSender.sendMessage(this, "Forum URL: http://www.runeresort.forumotion.com ");
                    	ServerMess = 61;
                    	break;
                    case 3:
                    	this.actionSender.sendMessage(this, "Please view our forums daily to see if there have been");
                    	this.actionSender.sendMessage(this, "any recent, and 1337 updates!");
                    	ServerMess = 61;
			break;
                    case 4:
                    case 8:
			this.actionSender.sendMessage(this, "If you like the server, Donate to keep it alive!");
			this.actionSender.sendMessage(this, "To donate, visit the site: http://www.runeresort.forumotion.com");
			ServerMess = 61;
			break;
                    }
        }
        if (heightLevel == 4) {
            bhworld = true;
        }
        if (heightLevel == 0) {
            bhworld = false;
        }
        if (proupdate > 0) {
            proupdate--;
            updatez = true;
        }
        if (casttdelay > 0) {
            casttdelay--;
        }
        if (proupdate > 1) {
            this.actionSender.setOverlay(this, 524);
            this.actionSender.setString(this, "Update!", 524, 1);
            this.actionSender.setString(this, "Update in " + proupdate + " seconds", 524, 2);
            this.actionSender.sendMessage(this, "Update.");
        }
        if (updatez) {
            this.actionSender.setOverlay(this, 524);
            this.actionSender.setString(this, "Update!", 524, 1);
            this.actionSender.setString(this, "Update in " + proupdate + " seconds", 524, 2);
            this.actionSender.sendMessage(this, "Update.");
        }
        if (proupdate == 0 && updatez == true) {
            System.out.println("Update Complete.");
            System.out.println("Update Complete.");
            System.out.println("Update Complete.");
            System.out.println("Update Complete.");
            System.out.println("Update Complete.");
            System.out.println("Update Complete.");
            System.out.println("Update Complete.");
            System.out.println("Update Complete.");
            System.out.println("Update Complete.");
            System.out.println("Update Complete.");
            System.out.println("Update Complete.");
            System.out.println("Update Complete.");
            System.out.println("Update Complete.");
            System.out.println("Update Complete.");
            System.out.println("Update Complete.");
            System.out.println("Update Complete.");
            this.disconnected[50] = true;


        }
        if (freezeDelay > 0) {
            freezeDelay--;
        }
        if (turkeydelay == 28) {
            requestAnim(10994, 0);
        }
        if (turkeydelay == 27) {
            requestGFX(1714, 0);
        }
        if (turkeydelay == 26) {
            requestAnim(10996, 0);
            npcType = 8499;
            updateReq = true;
            appearanceUpdateReq = true;
        }
        if (turkeydelay == 18) {
            requestAnim(10995, 0);
            requestGFX(1714, 0);
            npcType = -1;
            updateReq = true;
            appearanceUpdateReq = true;
            turkeydelay = -1;
        }
        if (turkeydelay > 0) {
            turkeydelay--;
        }
        if (vengeanceDelay > 0) {
            vengeanceDelay--;
        }
        if (spellbookSwapTimer > 0) {
            spellbookSwapTimer--;
        } else if (spellbookSwap) {
            actionSender.setTab(this, 79, spellbook);
            spellbookSwap = false;
            usedSpellbookSwap = false;
        }
        if (attackedBy != null) {
            count++;
            if (count == 6) {
                attackedBy = null;
                attackedByCount--;
                count = 0;
            }
        }
        if (logoutTimer > 0) {
            logoutTimer--;
        }
        if (procast > 0) {
            procast--;
        }
        if (restoreSpecialTimer > 0) {
            restoreSpecialTimer--;
        }
        if (antifire > 0) {
        	antifire--;
        }
        if (antifire == 1) {
        	actionSender.sendMessage(this, "Your antifire potion's effectiveness has worn off!");
        }
        if (antifire == 100) {
        	actionSender.sendMessage(this, "You have 1 minute until your Antifire Potion's effectiveness wears off!");
        }
    }


    /**
     * This method is called every 600 milliseconds.
     * <p>While this is good for for changing integers, this
     * should not be abused. Things that can be handled else where should
     * be done in that way, such as clicking the accept button in trade
     * should update in the ActionsButton class rather than Reqing
     * an update for the process to handle.
     */

    public void attackPlayer() {
        PlayerCombat pc = new PlayerCombat(this);
        pc.attackPlayer();
    }

    public int count;
    public boolean usedLogout;

    public void process() {
		if (FamiliarID > 0)
	{
		NPC np = Engine.npcs[FamiliarID];
		getActionSender().animateInterfaceId(this, 9850, 663, 3);
		getActionSender().setNPCId(this, np.npcType, 663, 3);
	}

	if (SummonDelay > 0)
	{
		SummonDelay--;
	}


        // Skill processes
        woodcutting.process();

        if (needsarrow) {
            Player p3 = Engine.players[this.bhTarget];
            this.actionSender.setHintIcon(p3, 10, 1, 1, -1);
        }
        if (jumpDelay > 0) {
            jumpDelay--;
            jumpUpdateReq = true;
        }

        if (jumpUpdateReq) {
            if (jumpDelay >= 1) {
                runEmote = walkEmote = 2750;
                updateReq = appearanceUpdateReq = true;
            }
            if (jumpDelay <= 0) {
                playerWeapon.setWeapon();
                jumpDelay = 0;
                updateReq = appearanceUpdateReq = true;
            }
            jumpUpdateReq = false;
        }

        if (DFSDelay > 0) {
            DFSDelay--;
        } else if (DFSDelay == 0) {
            append1Hit((int) Math.round(Math.random() * 25), 0);
            DFSDelay = -1;
        }

        if (leverTeleportDelay > 0) {
            leverTeleportDelay--;
        } else if (leverTeleportDelay == 0) {
            teleportTo(leverTeleportX, leverTeleportY, leverTeleportH, 4, 0, 8939, 8941, 1576, 0, 1577, 0);
            lever = false;
            leverTeleportDelay--;
        }

        if (teleblocked && teleblockTimer > 0) {
            if (teleblockTimer == 500) {
                actionSender.sendMessage(this, "You have been teleport blocked!");
                if (usingPrayer(17)) {
                    teleblockTimer = 250;
                }
            }
            teleblockTimer--;
        }
        if (teleblockTimer == 0) {
            teleblocked = false;
            teleblockTimer = 500;
            //actionSender.sendMessage(this, "The teleport block has worn off.");
        }
	if (this.absX >= 2614 && this.absY >= 3158 && this.absX <= 2616 && this.absY <= 3170) {
		this.jailed = true;
		this.teleblocked = true;
		//this.jailTimer = 2000;
	}
	if (this.absX >= 2617 && this.absY >= 3158 && this.absX <= 2619 && this.absY <= 3170 && this.heightLevel == 0 
	  || this.absX >= 2612 && this.absY >= 3139 && this.absX <= 2619 && this.absY <= 3145 && this.heightLevel == 1) {
		this.jailed = false;
		this.teleblocked = false;
		//this.jailTimer = 0
	}
	if (this.absX >= 2607 && this.absY >= 3139 && this.absX <= 2611 && this.absY <= 3145 && this.heightLevel == 1) {
		this.jailed = true;
		this.teleblocked = true;
		//this.jailTimer = 6000;
	}
        if (degrades && equipment[3] == 13290) {
            degrade--;
            if (degrade == 0) {
                boolean deleted = false;
                PlayerItems playerItems = new PlayerItems();
                for (int i = 0; i < equipment.length; i++) {
                    if (equipment[i] == 13290) {
                        equipment[i] = -1;
                        equipmentN[i] = 0;
                        actionSender.setItems(this, 387, 28, 93, equipment, equipmentN);
                        actionSender.sendMessage(this, "Your Vesta's longsword has degraded into nothing.");
                        deleted = true;
                        break;
                    }
                }
                if (!deleted) {
                    for (int i = 0; i < items.length; i++) {
                        if (items[i] == 13290) {
                            playerItems.deleteItem(this, 13290, playerItems.getItemSlot(this, 13290), 1);
                            actionSender.sendMessage(this, "Your Vesta's longsword has degraded into nothing.");
                            deleted = true;
                            break;
                        }
                    }
                }
                if (!deleted) {
                    for (int i = 0; i < bankItems.length; i++) {
                        if (bankItems[i] == 13290) {
                            bankItemsN[i]--;
                            if (bankItemsN[i] <= 0) {
                                bankItems[i] = -1;
                            }
                            actionSender.setItems(this, -1, 64207, 95, bankItems, bankItemsN);
                            actionSender.setItems(this, -1, 64209, 93, items, itemsN);
                            actionSender.setItems(this, 149, 0, 93, items, itemsN);
                            actionSender.sendMessage(this, "Your Vesta's longsword has degraded into nothing.");
                            break;
                        }
                    }
                }
                degrade = 6000;
                degrades = false;
            }
        }


        if (magicGraphicDelay > 0) {
            magicGraphicDelay--;
        } else if (magicGraphicDelay == 0) {
            playerMagic.appendGraphic(spellbook, spell);
            magicGraphicDelay--;
        }
        if (magicDamageDelay > 0) {
            magicDamageDelay--;
        } else if (magicDamageDelay == 0) {
            playerMagic.appendDamage(spellbook, spell);
            magicDamageDelay--;
        }
        if (magicAffectDelay > 0) {
            magicAffectDelay--;
        } else if (magicAffectDelay == 0) {
            playerMagic.appendAffect(spellbook, spell);
            magicAffectDelay--;
        }
        // Basically same as above, for npcs
        if (magicGraphicDelayNpc > 0) {
            magicGraphicDelayNpc--;
        } else if (magicGraphicDelayNpc == 0) {
            playerMagic.appendGraphicNpc(magicNpcSpellbook, magicNpcSpell);
            magicGraphicDelayNpc--;
        }
        if (magicDamageDelayNpc > 0) {
            magicDamageDelayNpc--;
        } else if (magicDamageDelayNpc == 0) {
            playerMagic.appendDamageNpc(magicNpcSpellbook, magicNpcSpell);
            magicDamageDelayNpc--;
        }

        if (usingPrayer()) {
            drainCount += prayerDrain();
            if (!isDead) {
                if (drainCount >= 1) {
                    skillLvl[5]--;
                    actionSender.setSkillLvl(this, 5);
                    drainCount--;
                }
            }
            if (skillLvl[5] <= 0) {
                skillLvl[5] = 0;
                actionSender.addSoundEffect(this, 2672, 1, 0, 0);
                actionSender.setSkillLvl(this, 5);
                actionSender.sendMessage(this, "You have run out of Prayer points; you must recharge at an altar.");
                resetPrayer();
            }
        }
        if (absX != -1 && absY != -1 && !disconnected[1] && this != null) {
            if (disconnected[0] && (usedLogout || attackedBy == null)) {
                try {
                    saveCharacter();
                } catch (Exception e) {
                }

                if (pTrade.getPartner() != null) {
                    pTrade.declineTrade();
                }
                if (clanRoom.length() > 0) {
                    Engine.clanChat.leave(this);
                }
                disconnected[1] = true;
            }
        }
        if (nextGraphicDelay > 0)
            nextGraphicDelay--;
        if (nextGraphicDelay == 0) {
            PlayerCombat playerAttacking = new PlayerCombat(this);
            playerAttacking.addNextAttack();
        }
        if (nextDamageDelay > 0)
            nextDamageDelay--;
        if (nextDamageDelay == 0) {
            PlayerCombat playerAttacking = new PlayerCombat(this);
            playerAttacking.addNextDamage();
        }
        if (summonTeleDelay > 0) {
            summonTeleDelay--;
        }
        if (summonTeleDelay == 0) {
            setCoords(3069, 10257, 4);
            summonTeleDelay = -1;
            requestAnim(715, 0);
        }
        if (summonDrainDelay > 0) {
            summonDrainDelay--;
        }
        if (summonDrainDelay == 0) {
            if (skillLvl[23] > 0) {
                skillLvl[23]--;
                actionSender.setSkillLvl(this, 23);
                summonDrainDelay = 14;
            } else {
                familiarDissMiss = true;
                summonedFamiliar = false;
                summonDrainDelay = -1;
                actionSender.sendMessage(this, "You ran out of Summoning skill points, Please restore them.");
            }
        }
        if (deathEmoteDelay > 0) {
            deathEmoteDelay--;
        }
        if (deathEmoteDelay == 0) {
            //requestAnim(9055, 0); //836, 2261
            requestAnim(10977, 0); //836, 2261
            if (usingPrayer(22)) {
                requestGFX(437, 0);
                if (multiwayCombatZone(absX, absY)) {
                    try {
                        for (Player player : Engine.players) {
                            if (Misc.getDistance(absX, absY, player.absX, player.absY) <= 1) {
                                player.append1Hit(getRandom((int) Math.floor(getLevelForXP(5) * 0.25)), 0);
                            }
                        }
                    } catch (Exception e) {
                    }
                } else {
                    try {
                        Server.engine.players[hitIndex].append1Hit(getRandom((int) Math.floor(getLevelForXP(5) * 0.25)), 0);
                    } catch (Exception e) {
                    }
                }
            }
            isDead = true;
            deathDelay = 4;
            deathEmoteDelay = -1;
        }
        if (massYellDelay > 0) {
            massYellDelay--;
        }
        if (clickDelay > 0) {
            clickDelay--;
        }
        if (teleDelay > 0) {
            teleDelay--;
        }
        if (equipSpecDelay > 0) {
            equipSpecDelay--;
        }
        if (countDelay > 0) {
            countDelay--;
        }
        if (countDelay == 0) {
            if (countType >= 0) {
                if (countType == 3) {
                    requestForceChat("3");
                } else if (countType == 2) {
                    requestForceChat("2");
                } else if (countType == 1) {
                    requestForceChat("1");
                } else if (countType == 0) {
                    requestForceChat("FIGHT!");
                }
                countType--;
                countDelay = 3;
            } else {
                countType = -1;
                countDelay = -1;
            }
        }
        if (explodeDelay > 0) {
            explodeDelay--;
        }
        if (explodeDelay == 0) {
            appendPotion();
        }
        if (rangeDmgDelay > 0) {
            rangeDmgDelay--;
        }
        if (rangeDmgDelay == 0) {
            PlayerCombat PC2 = new PlayerCombat(this);
            PC2.appendRangeDamage();
        }
        if (rangeDmgDelay2 > 0) {
            rangeDmgDelay2--;
        }
        if (rangeDmgDelay2 == 0) {
            PlayerCombat PC2 = new PlayerCombat(this);
            PC2.appendRangeDamage();
        }
        if (damageSpecDelay > 0) {
            damageSpecDelay--;
        }
        if (damageSpecDelay == 0 && enableSpecDamage) {
            PlayerCombat playCb2 = new PlayerCombat(this);
            playCb2.appendNpcDamageMeleeSpec();
        }
        if (damageDelay1 > 0) {
            damageDelay1--;
        }
        if (damageDelay1 == 0 && enableDamage) {
            PlayerCombat playerCb = new PlayerCombat(this);
            playerCb.appendNpcDamageMelee();
        }
        if (atkDelay > 0) {
            atkDelay--;
        }
        if (atkDelay == 0 && attackingNpc) {
            PlayerCombat playCb = new PlayerCombat(this);
            playCb.attackNpc();
        }
        if (buryDelay > 0) {
            buryDelay--;
        }
        if (battleCDelay > 0) {
            battleCDelay--;
        }
        if (battleCDelay == 0) {
            battleCount = 0;
            battleCDelay = -1;
        }
        if (pickPocketDelay > 0) {
            pickPocketDelay--;
        }
        if (skullVanishDelay > 0) {
            skullVanishDelay--;
        }
        if (skullVanishDelay == 0 && isSkulled) {
            headIconSkull = -1;
            isSkulled = false;
            skullVanishDelay = 0;
            appearanceUpdateReq = true;
            updateReq = true;
        }
        if (eatDelay > 0) {
            eatDelay--;
        }
        if (drinkDelay > 0) {
            drinkDelay--;
        }

        if (statDelay > 0) {
            statDelay -= usingPrayer(8) ? 2 : 1;
        } else {
            updateStats();
        }
        if (hpDelay > 0) {
            hpDelay -= usingPrayer(9) ? 2 : 1;
        } else {
            restoreHP();
        }

        if (poisonDelay > 0) {
            poisonDelay--;
        }
        /*if (isPoisoned && poisonDelay == 0) {
            double intreval = (poisonHitCount / 3) - poisonIntrevals;
            if (poisonHitCount == 0) {
                poisonDamage = getStartingPoisonDamage(Engine.players[enemyIndex]);
            } else if (intreval == 1) {
                poisonIntrevals++;
                poisonDamage -= poisonIntrevals;
            }
            if (poisonDamage == 0) {
                isPoisoned = false;
                poisonHitCount = 0;
                poisonIntrevals = 0;
                actionSender.sendMessage(this, "The poison wears off.");
                return;
            }
            appendHit(poisonDamage, 1);
            poisonDelay = 100;
            poisonHitCount++;
        }*/

        if (specFillDelay > 0) {
            if (specAmount < 1000) {
                specFillDelay--;
            } else {
                specFillDelay = 50;
            }
        } else {
            if (specAmount < 1000) {
                if (specAmount - 100 > 900) {
                    specAmount = 1000;
                } else {
                    specAmount += 100;
                }
                actionSender.setConfig2(this, 300, specAmount);
            }
            specFillDelay = 50;
        }

        if (animClickDelay > 0) {
            animClickDelay--;
        }
        if (agilityDelay > 0) {
            agilityDelay--;
        }
        if (agilityDelay == 0 && agilityPerforming) {
            PlayerAgility pa = new PlayerAgility(this);
            pa.resetPerforming();
        }
        if (deathDelay > 0) {
            deathDelay--;
        }
        if (waitDeathDelay > 0) {
            waitDeathDelay--;
        }

        //if (skillLvl[3] <= 0 && waitDeathDelay == -1 && !randomVariable) {
        //    waitDeathDelay = 3;
        //    resetAttack();
        //    deathEmoteDelay = 3;
        //    if (duelFight())
        //	duelDeath = true;
        //    randomVariable = true;
        //    isDead = true;
        //}

        if (deathDelay == 0 && isDead) {
            appendDeath();
        }
        if (combatDelay > 0) {
            combatDelay--;
        }
        if (attackingPlayer) {
            attackPlayer();
        }
        if (damageDelay > 0) {
            damageDelay--;
        }
        if (damageDelay == 0) {
            PlayerCombat PC = new PlayerCombat(this);
            PC.appendDamages();
        }
        if (mageDelay > 0) {
            mageDelay--;
        }
        if (SummonDelay > 0) {
            SummonDelay--;
        }
        if (specDelay > 0) {
            specDelay--;
        }
        if (specDelay == 0) {
            PlayerCombat PC1 = new PlayerCombat(this);
            PC1.appendSpecDamage();
        }
        if (secondSpecDelay > 0) {
            secondSpecDelay--;
        }
        if (secondSpecDelay == 0) {
            PlayerCombat PC1 = new PlayerCombat(this);
            PC1.appendSecondSpecDamage();
        }
        if (delayedDamageDelay > 0) {
            delayedDamageDelay--;
        }
        if (delayedDamageDelay == 0) {
            PlayerCombat PC1 = new PlayerCombat(this);
            PC1.appendDelayedDamage(delayedDamageHit);
        }
        if (runEnergyDelay > 0) {
            runEnergyDelay--;
        } else {
            if (runEnergy < 100) {
                runEnergy++;
                runEnergyUpdateReq = true;
            }
            runEnergyDelay = 4;
        }
        if (itemPickup) {
            Engine.packets.pickupItem.handlePacket(this, 0, 0);
        }
        if (playerOption1) {
            Engine.packets.playerOption1.handlePacket(this, 0, 0);
        }
        if (playerOption2) {
            Engine.packets.playerOption2.handlePacket(this, 0, 0);
        }
        if (playerOption3) {
            Engine.packets.playerOption3.handlePacket(this, 0, 0);
        }
        if (npcOption1) {
            Engine.packets.npcOption1.handlePacket(this, 0, 0);
        }
        if (npcOption2) {
            Engine.packets.npcOption2.handlePacket(this, 0, 0);
        }
        if (objectOption1) {
            Engine.packets.objectOption1.handlePacket(this, 0, 0);
        }
        if (objectOption2) {
            Engine.packets.objectOption2.handlePacket(this, 0, 0);
        }
        if (runEnergyUpdateReq) {
            actionSender.setEnergy(this);
            runEnergyUpdateReq = false;
        }
        appendWilderness();
        if (teleDelay == 0) {
            teleDelay = -1;
            if (teletab) {
                requestAnim(teleFinishAnim, 0);
                requestGFX(teleFinishGFX, teleFinishGFXHeight);
                teleDelay = 2;
                teleFinishAnim = playerWeapon.getStandEmote(equipment[3]);
                teleFinishGFX = -1;
            } else {
                setCoords(teleX, teleY, teleH);
                if (teleFinishAnim != -1) {
                    requestAnim(teleFinishAnim, 0);
                }
                if (teleFinishGFX != -1) {
                    requestGFX(teleFinishGFX, teleFinishGFXHeight);
                }
            }
            if (!teletab) {
                teleX = teleY = -1;
            }
            teletab = false;
        }
        if (clickDelay == 0) {
            clickDelay = -1;
        }
    }

    public void potion(int potionID) {
        int root = 0;
        int toAdd = 0;
        int i = 0;
        switch (potionID) {
        case 2452: //antifire potion (4)
        case 2454: //antifire potion (3)
        case 2456: //antifire potion (2)
        case 2458: //antifire potion (1)
        	if (antifire > 0) {
        		actionSender.sendMessage(this, "You replenish your AntiFire's Effects!");
        		this.antifire = 500;
        	} else if (antifire == 0) {
        		actionSender.sendMessage(this, "You are now protected from fire for 5 minutes!");
        		this.antifire = 500;
        	} else if (antifire >= 450) {
        		actionSender.sendMessage(this, "You have just used your antifire potion! Why waste it?");
        	} else if (antifire == 100) {
        		actionSender.sendMessage(this, "You are down to 1 minute of Antifire Effectiveness.");
        	}
        	break;
        case 9739: //combat potion -aka-overload
        case 9741: //combat potion -aka-overload
        case 9743: //combat potion -aka-overload
        case 9745: //combat potion -aka-overload
        	root = getLevelForXP(0);
        	toAdd = 5 + (int) Math.round(root * 0.2);
        	if ((skillLvl[1] + toAdd) > (root + toAdd) && (skillLvl[2] + toAdd) > (root + toAdd) && (skillLvl[0] + toAdd) > (root + toAdd)) {
        		skillLvl[1] = root + toAdd;
        		skillLvl[0] = root + toAdd;
        		skillLvl[2] = root + toAdd;
        	} else {
        		skillLvl[1] += toAdd;
        		skillLvl[0] += toAdd;
        		skillLvl[2] += toAdd;
        	}
        	actionSender.setSkillLvl(this, 1);
        	actionSender.setSkillLvl(this, 0);
        	actionSender.setSkillLvl(this, 2);
        	break;
            case 2436:
            case 145:
            case 147:
            case 149:
                root = getLevelForXP(0);
                toAdd = 5 + (int) Math.round(root * 0.1414141414);
                if ((skillLvl[0] + toAdd) > (root + toAdd)) {
                    skillLvl[0] = root + toAdd;
                } else {
                    skillLvl[0] += toAdd;
                }
                actionSender.setSkillLvl(this, 0);
                break;

            case 2440:
            case 157:
            case 159:
            case 161:
                root = getLevelForXP(2);
                toAdd = 5 + (int) Math.round(root * 0.1414141414);
                if ((skillLvl[2] + toAdd) > (root + toAdd)) {
                    skillLvl[2] = root + toAdd;
                } else {
                    skillLvl[2] += toAdd;
                }
                actionSender.setSkillLvl(this, 2);
                break;

            case 2442:
            case 163:
            case 165:
            case 167:
                root = getLevelForXP(1);
                toAdd = 5 + (int) Math.round(root * 0.1414141414);
                if ((skillLvl[1] + toAdd) > (root + toAdd)) {
                    skillLvl[1] = root + toAdd;
                } else {
                    skillLvl[1] += toAdd;
                }
                actionSender.setSkillLvl(this, 1);
                break;

            case 2444:
            case 169:
            case 171:
            case 173:
                root = getLevelForXP(4);
                toAdd = 4 + (int) Math.round(root * 0.1509090909);
                if ((skillLvl[4] + toAdd) > (root + toAdd)) {
                    skillLvl[4] = root + toAdd;
                } else {
                    skillLvl[4] += toAdd;
                }
                actionSender.setSkillLvl(this, 4);
                break;

            case 3040:
            case 3042:
            case 3044:
            case 3046:
                if (skillLvl[6] + 4 > getLevelForXP(6) + 4) {
                    skillLvl[6] = getLevelForXP(6) + 4;
                } else {
                    skillLvl[6] += 4;
                }
                actionSender.setSkillLvl(this, 6);
                break;

            case 2428:
            case 121:
            case 123:
            case 125:
                root = getLevelForXP(0);
                toAdd = 3 + (int) Math.round(root * 0.0909090909);
                if ((skillLvl[0] + toAdd) > (root + toAdd)) {
                    skillLvl[0] = root + toAdd;
                } else {
                    skillLvl[0] += toAdd;
                }
                actionSender.setSkillLvl(this, 0);
                break;

            case 113:
            case 115:
            case 117:
            case 119:
                root = getLevelForXP(2);
                toAdd = 3 + (int) Math.round(root * 0.0909090909);
                if ((skillLvl[2] + toAdd) > (root + toAdd)) {
                    skillLvl[2] = root + toAdd;
                } else {
                    skillLvl[2] += toAdd;
                }
                actionSender.setSkillLvl(this, 2);
                break;

            case 2432:
            case 133:
            case 135:
            case 137:
                root = getLevelForXP(1);
                toAdd = 3 + (int) Math.round(root * 0.0909090909);
                if ((skillLvl[1] + toAdd) > (root + toAdd)) {
                    skillLvl[1] = root + toAdd;
                } else {
                    skillLvl[1] += toAdd;
                }
                actionSender.setSkillLvl(this, 1);
                break;

            case 2434:
            case 139:
            case 141:
            case 143:
                root = getLevelForXP(5);
                toAdd = 7 + (int) Math.round(root * 0.2424242424);
                if ((skillLvl[5] + toAdd) > root) {
                    if (skillLvl[5] < root) {
                        skillLvl[5] = root;
                    }
                } else {
                    skillLvl[5] += toAdd;
                }
                actionSender.setSkillLvl(this, 5);
                break;

            case 2430:
            case 127:
            case 129:
            case 131:
                while (i <= 6) {
                    if (i == 3 || i == 5) {
                        i++;
                    }
                    root = getLevelForXP(i);
                    toAdd = 10 + (int) Math.round(root * 0.2929292929);
                    if ((skillLvl[i] + toAdd) > root) {
                        if (skillLvl[i] < root) {
                            skillLvl[i] = root;
                        }
                    } else {
                        skillLvl[i] += toAdd;
                    }
                    actionSender.setSkillLvl(this, i);
                    i++;
                }
                break;

            case 3024:
            case 3026:
            case 3028:
            case 3030:
                while (i <= 23) {
                    if (i == 3) {
                        i++;
                    }
                    root = getLevelForXP(i);
                    toAdd = 8 + (int) Math.round(root * 0.2424242424);
                    if ((skillLvl[i] + toAdd) > root) {
                        if (skillLvl[i] < root) {
                            skillLvl[i] = root;
                        }
                    } else {
                        skillLvl[i] += toAdd;
                    }
                    actionSender.setSkillLvl(this, i);
                    i++;
                }
                break;

            case 6685:
            case 6687:
            case 6689:
            case 6691:
                while (i <= 6) {
                    if (i == 5) {
                        i++;
                    }
                    root = getLevelForXP(i);
                    if (i == 0 || i == 2 || i == 4 || i == 6) {
                        toAdd = -1 * (2 + (int) Math.round(root * 0.0707070707));
                        if ((skillLvl[i] + toAdd) < 0) {
                            skillLvl[i] = 0;
                        } else {
                            skillLvl[i] += toAdd;
                        }
                    } else {
                        toAdd = 2 + (int) Math.round(root * (i == 1 ? 0.1919191919 : 0.1414141414));
                        if (skillLvl[i] + toAdd > root + toAdd) {
                            skillLvl[i] = root + toAdd;
                        } else {
                            skillLvl[i] += toAdd;
                        }
                    }
                    actionSender.setSkillLvl(this, i);
                    i++;
                }
                break;

            case 2450:
            case 189:
            case 191:
            case 193:
                while (i <= 5) {
                    if (i == 4) {
                        i++;
                    }
                    root = getLevelForXP(i);
                    if (i == 5) {
                        toAdd = 9;
                        if (skillLvl[i] + toAdd > root) {
                            if (skillLvl[i] < root) {
                                skillLvl[i] = root;
                            }
                        } else {
                            skillLvl[i] += toAdd;
                        }
                        break;
                    }
                    if (i == 1 || i == 3) {
                        toAdd = -1 * (2 + (int) Math.round(root * 0.0909090909));
                        if (i == 3) {
                            append1Hit(-1 * toAdd, 0);
                        } else {
                            if ((skillLvl[i] + toAdd) < 0) {
                                skillLvl[i] = 0;
                            } else {
                                skillLvl[i] += toAdd;
                            }
                        }
                    } else {
                        toAdd = 2 + (int) Math.round(root * (i == 0 ? 0.1919191919 : 0.1111111111));
                        if (skillLvl[i] + toAdd > root + toAdd) {
                            skillLvl[i] = root + toAdd;
                        } else {
                            skillLvl[i] += toAdd;
                        }
                    }
                    actionSender.setSkillLvl(this, i);
                    i++;
                }
                break;
        }
        requestAnim(829, 0);
        actionSender.addSoundEffect(this, 2401, 1, 0, 0);
        combatDelay = 6;
        eatDelay = 3;
        drinkDelay = 3;
    }

    /**
     * DIALOGUE *
     */
    public int dialogueId = 0;
    public int dialogueOptionsId = 0;

    // 64 - One lined player dialogue
    // 65 - Two lined player dialogue
    // 66 - Three lined player dialogue
    // 67 - Four lined player dialogue
    public void sendPlayerDialogue(int id, String text) {
        actionSender.showChatboxInterface(this, 64);
        actionSender.animateInterfaceId(this, 9846, 64, 2);
        actionSender.setId(this, 64, 2);
        actionSender.setString(this, username2, 64, 3);
        actionSender.setString(this, text, 64, 4);
        this.dialogueId = id;
    }

    public void sendPlayerDialogue(int id, String text, String text2) {
        actionSender.showChatboxInterface(this, 65);
        actionSender.animateInterfaceId(this, 9846, 65, 2);
        actionSender.setId(this, 65, 2);
        actionSender.setString(this, username2, 65, 3);
        actionSender.setString(this, text, 65, 4);
        actionSender.setString(this, text2, 65, 5);
        this.dialogueId = id;
    }

    public void sendPlayerDialogue(int id, String text, String text2, String text3) {
        actionSender.showChatboxInterface(this, 66);
        actionSender.animateInterfaceId(this, 9846, 66, 2);
        actionSender.setId(this, 66, 2);
        actionSender.setString(this, username2, 66, 3);
        actionSender.setString(this, text, 66, 4);
        actionSender.setString(this, text2, 66, 5);
        actionSender.setString(this, text3, 66, 6);
        this.dialogueId = id;
    }

    public void sendPlayerDialogue(int id, String text, String text2, String text3, String text4) {
        actionSender.showChatboxInterface(this, 67);
        actionSender.animateInterfaceId(this, 9846, 67, 2);
        actionSender.setId(this, 67, 2);
        actionSender.setString(this, username2, 67, 3);
        actionSender.setString(this, text, 67, 4);
        actionSender.setString(this, text2, 67, 5);
        actionSender.setString(this, text3, 67, 6);
        actionSender.setString(this, text4, 67, 7);
        this.dialogueId = id;
    }

    public void sendNpcDialogue(int id, int npcId, String npcName, String text, String text2) {
        actionSender.showChatboxInterface(this, 242);
        actionSender.animateInterfaceId(this, 9827, 242, 2);
        actionSender.setNPCId(this, npcId, 242, 2);
        actionSender.setString(this, npcName, 242, 3);
        actionSender.setString(this, text, 242, 4);
        actionSender.setString(this, text2, 242, 5);
        this.dialogueId = id;
    }

    public void sendNpcDialogueNew(int id, int npcId, int emoteId, String npcName, String text, String text2) {
        actionSender.showChatboxInterface(this, 242);
        actionSender.animateInterfaceId(this, emoteId, 242, 2);
        actionSender.setNPCId(this, npcId, 242, 2);
        actionSender.setString(this, npcName, 242, 3);
        actionSender.setString(this, text, 242, 4);
        actionSender.setString(this, text2, 242, 5);
        this.dialogueId = id;
    }


    public void sendDialogueOptions(int id, String option1, String option2) {
        actionSender.setString(this, option1, 229, 2);
        actionSender.setString(this, option2, 229, 3);
        actionSender.showChatboxInterface(this, 229);
        this.dialogueOptionsId = id;
    }

    public void sendDialogueOptions(int id, String option1, String option2, String option3) {
        actionSender.setString(this, option1, 458, 1);
        actionSender.setString(this, option2, 458, 2);
        actionSender.setString(this, option3, 458, 3);
        actionSender.showChatboxInterface(this, 458);
        this.dialogueOptionsId = id;
    }

    public void sendDialogueOptions(int id, String option1, String option2, String option3, String option4,
                                    String option5) {
        actionSender.setString(this, option1, 238, 1);
        actionSender.setString(this, option2, 238, 2);
        actionSender.setString(this, option3, 238, 3);
        actionSender.setString(this, option4, 238, 4);
        actionSender.setString(this, option5, 238, 5);
        actionSender.showChatboxInterface(this, 238);
        this.dialogueOptionsId = id;
    }

    public void food(int foodID) {
        int healAmount = 0;
        int toDelayCombat = 6;
        int toDelayEat = 3;
        switch (foodID) {
            case 10476:
                healAmount = 1 + Misc.random(2);
                runEnergy += runEnergy * .10;
                runEnergyUpdateReq = true;
                if (runEnergy + (runEnergy * .10) > 100) {
                    runEnergy = 100;
                }
                break;
            case 373:
                healAmount = 14;
                break;
            case 379:
                healAmount = 12;
                break;
            case 385:
                healAmount = 20;
                break;
            case 391:
                healAmount = 22;
                break;
            case 3144:
                healAmount = 18;
                toDelayCombat = combatDelay;
                drinkDelay = 3;
                break;
            case 7060:
                healAmount = 22;
                break;
            case 7946:
                healAmount = 16;
                break;
        }
        requestAnim(829, 0);
        actionSender.addSoundEffect(this, 2393, 1, 0, 0);
        updateHP(healAmount, true);
        actionSender.sendMessage(this, "You eat the " + Engine.items.getItemName(foodID) + ".");
        combatDelay = toDelayCombat;
        eatDelay = toDelayEat;
    }

    public String lastKilled = "";

    public boolean receivesPVPRewards(Player p, Player opp) {
        if (Server.socketListener.getAddress(p.socket.socket).equals(Server.socketListener.getAddress(opp.socket.socket))) {
            return false;
        }
        return true;
    }

    public void appendDeath() {
        if (deathDelay == 0 && isDead) {
            Player opp = Server.engine.players[hitIndex];
            try {
                if (!funPkZone(absX, absY)) {
                    // No Drops in Fun pk,
                    dropStuff(opp != null ? opp.username : "");
                }
                if (opp != null) {
                    actionSender.sendMessage(opp, getKillMessage(username));
                    if (!funPkZone(absX, absY)) {
                        // No kill counts in funpk, lol
                        if (receivesPVPRewards(this, opp)) {
                            opp.kills++;
                            opp.totalKills++;
                            DC++;
                            opp.KC++;
                        }
                    }
                    opp.lastKilled = Server.socketListener.getAddress(socket.socket);
                    appendData("characters/logs/kills/" + opp.username + ".txt", opp.username+" Was killed By: "+username);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            for (int i = 0; i < skillLvl.length; i++) {
                skillLvl[i] = getLevelForXP(i);
                actionSender.setSkillLvl(this, i);
            }
            for (int i = 0; i < 1000; i++) {
                requestAnim(playerWeapon.getStandEmote(equipment[3]), 0);
            }

            if (opp != null) {
                opp.attacking = null;
                opp.attackedBy = null;
                opp.oppIndex = 0;
                opp.hitIndex = 0;
                opp.resetAttack();
                opp.requestFaceTo(65535);
            }
            //BhTarg.getTarget(this);
            attacking = null;
            attackedBy = null;
            oppIndex = 0;
            hitIndex = 0;
            resetAttack();

            setCoords(2440, 3090, 0);
            // Overlays
            actionSender.removeOverlay(this);
            removedWildy = false;
            wildernessZone(absX, absY);
            actionSender.sendMessage(this, "Oh dear, you have died.");

            deathDelay = -1;
            isDead = false;

            magicGraphicDelay = -1;
            magicDamageDelay = -1;

            initialAttack = false;
            isSkulled = false;
            headIconSkull = -1;
            skullVanishDelay = 0;

            isPoisoned = false;
            poisonHitCount = 0;
            poisonDelay = 0;

            specAmount = 1000;
            actionSender.setConfig2(this, 300, 1000);

            resetPrayer();

            actionSender.removeOverlay(this);

            appearanceUpdateReq = true;
            updateReq = true;
        }
    }

    public void resetAttack() {
        attackingPlayer = false;
        attacking = "";
        if (oppIndex != -1) {
            if (Engine.players[oppIndex] != null) {
                Engine.players[oppIndex].underAttack = false;
            }
        }
        enemyIndex = 0;
        oppIndex = 0;
        //hitIndex = 0;
        hitOne = false;
        hitTwo = false;
        hitThree = false;
        hitFour = false;
        hit1 = 0;
        hit2 = 0;
        hit3 = 0;
        hit4 = 0;
        specDelay = -1;
        secondSpecDelay = -1;
    }

    /**
     * Get xp based on your level.
     *
     * @param skillId The skill level to get the level based off XP for.
     * @return Returns the level based on the amount of XP the specified skill has.
     */
    public int getLevelForXP(int skillId) {
        int exp = skillXP[skillId];
        int points = 0;
        int output = 0;
        for (int lvl = 1; lvl < 100; lvl++) {
            points += Math.floor((double) lvl + 300.0 * Math.pow(2.0, (double) lvl / 7.0));
            output = (int) Math.floor(points / 4);
            if ((output - 1) >= exp) {
                return lvl;
            }
        }
        return 99;
    }

    public int getXPForLevel(int level) {
        int points = 0;
        int output = 0;

        for (int lvl = 1; lvl <= level; lvl++) {
            points += Math.floor((double) lvl + 300.0 * Math.pow(2.0, (double) lvl / 7.0));
            if (lvl >= level) {
                return output;
            }
            output = (int) Math.floor(points / 4);
        }
        return 0;
    }

    /**
     * Calculates equipment bonus.
     */
    public void calculateEquipmentBonus() {
        for (int i = 0; i < equipmentBonus.length; i++) {
            equipmentBonus[i] = 0;
        }
        for (int i = 0; i < equipment.length; i++) {
            if (equipment[i] > -1) {
                for (int j = 0; j < Engine.items.maxListedItems; j++) {
                    if (Engine.items.itemLists[j] != null) {
                        if (Engine.items.itemLists[j].itemId == equipment[i]) {
                            for (int k = 0; k < equipmentBonus.length; k++) {
                                equipmentBonus[k] += Engine.items.itemLists[j].bonuses[k];
                            }
                            break;
                        }
                    }
                }
            }
        }
    }

    /**
     * Writes the equipment bonus.
     */
    public void setEquipmentBonus() {
        String[] bonusNames = Misc.bonusNames;
        int id = 35;
        for (int i = 0; i < equipmentBonus.length; i++) {
            actionSender.setString(this, bonusNames[i] + ": " + (equipmentBonus[i] >= 0 ? "+" : "") + equipmentBonus[i], 667, id++);
            if (id == 45) {
                id = 47;
            }
        }
        actionSender.setString(this, "Summoning: +0", 667, 45);
    }

    /**
     * Alching
     */
    public long lastAlch = 0;

	public void openBank() {
		actionSender.setConfig2(this, 563, 4194304); //???
		actionSender.setConfig(this, 115, withdrawNote ? 1 : 0);
		actionSender.setConfig(this, 305, insertMode ? 1 : 0);
		Engine.playerBank.sendTabConfig(this);
		actionSender.showInterface(this, 762);
		actionSender.setInventory(this, 763);
		actionSender.setBankOptions(this);
		actionSender.setItems(this, -1, 64207, 95, bankItems, bankItemsN);
		actionSender.setItems(this, -1, 64209, 93, items, itemsN);
		//actionSender.hideTabs(this);// code to hide inventory & tabs
		actionSender.setInterfaceConfig(this, 762, 18, true); //Hide some buttons
		actionSender.setInterfaceConfig(this, 762, 19, true); //Remove it
		actionSender.setInterfaceConfig(this, 762, 23, true); //If ya want
		viewingBankTab = 10;
		actionSender.setString(this, "Bank of Rune Resort", 762, 24);
		actionSender.setString(this, ""+Engine.playerBank.getFreeBankSlot(this), 762, 97);
		actionSender.setString(this, ""+Engine.playerBank.SIZE, 762, 98);
	}

    public void updateHP(int difference, boolean heal) {
        if (skillLvl[3] == 0) {
            return;
        }
        if (heal) {
            skillLvl[3] += difference;
            if (skillLvl[3] > getLevelForXP(3)) {
                skillLvl[3] = getLevelForXP(3);
            }
        } else if (!heal) {
            skillLvl[3] -= difference;
            if (skillLvl[3] <= 0) {
                skillLvl[3] = 0;
                deathEmoteDelay = 3;
                isDead = true;
                attacking = null;
                attackedBy = null;
                Engine.playerMovement.resetWalkingQueue(this);
                requestFaceTo(65535);
            }
        }
        actionSender.setSkillLvl(this, 3);
        if ((skillLvl[3] <= Math.round(getLevelForXP(3) * 0.10) && skillLvl[3] > 0) && usingPrayer(23)) {
            requestGFX(436, 0);
            actionSender.addSoundEffect(this, 2681, 1, 0, 0);
            skillLvl[3] += Math.round(getLevelForXP(5) * 0.25);
            skillLvl[5] = 0;
            actionSender.setSkillLvl(this, 5);
        }
    }

    /**
     * Teleport to Clan Wars portal room
     */
    public void teleportToClanWars() {
        teleportTo(3271, 3684, 4);
    }

    /**
     * Teleports a player.
     *
     * @param x          The x coordinate to teleport to.
     * @param y          The y coordinate to teleport to.
     * @param height     The height level to teleport to.
     * @param delay      The delay before the teleport is done.
     * @param distance   The offset you can teleport to, such as 1 for a max offset of x +/- 1 and y +/- 1.
     * @param emoteStart The emote to do right away.
     * @param emoteEnd   The emote to do after teleporting.
     * @param gfxStart   The graphic to do right away.
     * @param gfxStartH  The height level to create the start graphic at.
     * @param gfxEnd     The graphic to do after the teleport is done.
     * @param gfxEndH    The finish graphic height.
     */
    public boolean teleportTo(int x, int y, int height, int delay, int distance, int emoteStart, int emoteEnd, int gfxStart,
                              int gfxStartH, int gfxEnd, int gfxEndH) {
        if (!forceTeleporting) {
            if (teleblocked) {
                actionSender.sendMessage(this, "You are teleport blocked!");
                return false;
            }
            if ((attackingPlayer || freezeDelay > 0 ||
                    (underAttack))) {
                message("You cannot teleport away from combat!");
                return false;
            }
        }
        itemPickup = false;
        playerOption1 = false;
        playerOption2 = false;
        playerOption3 = false;
        npcOption1 = false;
        npcOption2 = false;
        objectOption1 = false;
        objectOption2 = false;
        attackingPlayer = false;
        clickDelay = delay + 2;
        teleDelay = delay;
        if (distance > 0) {
            int xType = Misc.random(1);
            int yType = Misc.random(1);
            int xOffset = Misc.random(distance);
            int yOffset = Misc.random(distance);
            if (xType == 1)
                x += -xOffset;
            else
                x += xOffset;
            if (yType == 1)
                y += -yOffset;
            else
                y += yOffset;
        }
loadStaticObjects();
        teleX = x;
        teleY = y;
        teleH = height;
        Engine.playerMovement.resetWalkingQueue(this);
        requestAnim(emoteStart, 0);
        requestGFX(gfxStart, gfxStartH);
        teleFinishGFX = gfxEnd;
        teleFinishGFXHeight = gfxEndH;
        teleFinishAnim = emoteEnd;
        forceTeleporting = false; // Incase they were force teleporting (:
        // Overlays
        //actionSender.removeOverlay(this);
        //removedWildy = false;
        //wildernessZone(absX, absY);
        return true;
    }

    /**
     * Set the player's coordinates.
     *
     * @param x The x coordinate to teleport to.
     * @param y The y coordinate to teleport to.
     */
    public void setCoords(int x, int y, int height) {
        teleportToX = x;
        teleportToY = y;
        heightLevel = height;
        didTeleport = true;
    }

    public void setCoords(int x, int y) {
        // Sets coords on the same height level
        teleportToX = x;
        teleportToY = y;
        //heightLevel = this.heightLevel; // Not needed
        didTeleport = true;
    }

    /**
     * Req an animation for this player.
     *
     * @param animId The amination to perform.
     * @param animD  The delay before doing the animation.
     */
    public void requestAnim(int animId, int animD) {
        animReq = animId;
        animDelay = animD;
        animUpdateReq = true;
        updateReq = true;
    }

    /**
     * Req an graphic for this player.
     *
     * @param gfxId The graphic to perform.
     * @param gfxD  The delay or height or the gfx depending on the value.
     */
    public void requestGFX(int gfxId, int gfxD) {
        if (gfxD >= 100) {
            gfxD += 6553500;
        }
        gfxReq = gfxId;
        gfxDelay = gfxD;
        gfxUpdateReq = true;
        updateReq = true;
    }

    public void replaceDoors() {
        // FACE: 0= WEST | -1 = NORTH | -2 = EAST | -3 = SOUTH
        // ObjectType: 0-3 wall objects, 4-8 wall decoration, 9: diag.
        // walls, 10-11 world objects, 12-21: roofs, 22: floor decoration
        for (int d = 0; d < Engine.doorHandler.doorX.length; d++) {
            if ((clickId == Engine.doorHandler.doorId[d]) && (clickX == Engine.doorHandler.doorX[d])
                    && (clickY == Engine.doorHandler.doorY[d])) {
                int newFace = Engine.doorHandler.doorFaceOpen[d];
                for (int j = 0; j < Engine.players.length; j++) {
                    Player player = Engine.players[j];
                    if (player == null)
                        continue;
                    if ((player.username != null)
                            && (player.heightLevel == heightLevel)
                            && !player.disconnected[0] && (player.absY > 0)
                            && (player.absX > 0)) {
                        if (Misc.getDistance(player.absX, player.absY, Engine.doorHandler.doorX[d],
                                Engine.doorHandler.doorY[d]) <= 17) {
                            Engine.actionSender.addObject(player, Engine.doorHandler.doorId[d],
                                    Engine.doorHandler.doorHeight[d], Engine.doorHandler.doorX[d],
                                    Engine.doorHandler.doorY[d], newFace, 0);
                        }
                    }
                }
            }
        }
    }

    /**
     * Req this player faces NPC or player.
     *
     * @param faceId The target to face.
     */
    public void requestFaceTo(int faceId) {
        faceToReq = faceId;
        faceToUpdateReq = true;
        updateReq = true;
    }

    int poisonDamage;
    int poisonIntrevals = 0;

    public int getStartingPoisonDamage(Player p2) {
        String name = "";
        int damage = 0;
        boolean usingRange = false;
        if ((p2.equipment[3] >= 839 && p2.equipment[3] <= 861) || (p2.equipment[3] >= 9174 && p2.equipment[3] <= 9185) || p2.equipment[3] == 11235) { //Ranged
            name = Engine.items.getItemName(equipment[13]);
            usingRange = true;
        } else { //Melee
            name = Engine.items.getItemName(p2.equipment[3]);
        }
        if (name.contains("(p++)")) {
            damage = usingRange ? 4 : 6;
        }
        if (name.contains("(p+)")) {
            damage = usingRange ? 3 : 5;
        }
        if (name.contains("(p)")) {
            damage = usingRange ? 2 : 4;
        }
        return damage;
    }

    public int totalDamageRecoiled;

    public void appendNPCHit(int damage, int poison) {
        if (damage > skillLvl[3]) {
            damage = skillLvl[3];
        }
        updateHP(damage, false);
        if (!hit1UpdateReq) {
            hitDiff1 = damage;
            poisonHit1 = poison;
            hit1UpdateReq = true;
        } else {
            hitDiff2 = damage;
            poisonHit2 = poison;
            hit2UpdateReq = true;
        }
        updateReq = true;
    }

    public void appendHit(int damage, int poison) {
        Player opp = Server.engine.players[hitIndex];
        if (opp != null) {
            if (opp.isDead) {
                return;
            }

            if (damage > skillLvl[3]) {
                damage = skillLvl[3];
            }
            updateHP(damage, false);
            if (autoRetaliate) {
                enemyIndex = hitIndex;
                attackingPlayer = true;
            }
            int[] skill = {-1, -1, -1};
            if (!usingMage) {
                switch (opp.attackStyle()) {
                    case 1:
                        skill[0] = 0;
                        skill[1] = 0;
                        skill[2] = 0;
                        break;
                    case 2:
                        skill[0] = 2;
                        skill[1] = 2;
                        skill[2] = 2;
                        break;
                    case 3:
                        skill[0] = 1;
                        skill[1] = 1;
                        skill[2] = 1;
                        break;
                    case 4:
                        skill[0] = 0;
                        skill[1] = 1;
                        skill[2] = 2;
                        break;
                    case 5:
                    case 6:
                        skill[0] = 4;
                        skill[1] = 4;
                        skill[2] = 4;
                        break;
                    case 7:
                        opp.appendExperience((damage * 500), 4);
                        opp.appendExperience((damage * 500), 1);
                        opp.appendExperience((damage * 500), 3);
                        break;
                }
                for (int i : skill) {
                    if (i != -1) {
                        opp.appendExperience((damage * 500), i);
                    }
                }
                opp.appendExperience((damage * 500), 3);
            }
            if (opp.usingPrayer(24) && poison == 0) { //Smite
                if (skillLvl[5] - (int) Math.round(damage * 0.25) > 0) {
                    skillLvl[5] -= (int) Math.round(damage / 4);
                    actionSender.setSkillLvl(this, 5);
                } else {
                    skillLvl[5] = 0;
                    actionSender.setSkillLvl(this, 5);
                }
            }
            if (vengeance && poison == 0) { //Vengeance
                if (damage > 0) {
                    if (skillLvl[3] > 0) {

                        opp.append1Hit(((int) Math.floor(damage * 0.75)), 0);
                    } else {
                        opp.append1Hit(0, 0);
                    }
                    requestForceChat("Taste vengeance!");
                    vengeance = false;
                }
            }
            if (equipment[12] == 2550 && poison == 0) { //Ring of recoil
            	if (damage > 0) {
            		if (skillLvl[3] > 0) {
            			int recoil = 1 + ((int) Math.floor(damage * 0.40));
            			opp.append1Hit(recoil, 0);
            			totalDamageRecoiled += recoil;
            			if (totalDamageRecoiled >= 40) {
            				equipment[12] = -1;
            				equipmentN[12] = 0;
            				actionSender.setItems(this, 387, 28, 93, equipment, equipmentN);
            				actionSender.sendMessage(this, "Your ring of recoil has shattered.");
            				totalDamageRecoiled = 0;
            			}
            		} else {
            			opp.append1Hit(0, 0);
            		}
            	}
            }
            if (opp.barrowsSet(3) && poison == 0) { //Guthans affect
                if (Math.random() <= 0.25) {
                    opp.updateHP(damage, true);
                    requestGFX(398, 0);
                }
            }
            if (!hit1UpdateReq) {
                hitDiff1 = damage;
                poisonHit1 = poison;
                hit1UpdateReq = true;
            } else {
                hitDiff2 = damage;
                poisonHit2 = poison;
                hit2UpdateReq = true;
            }
            updateReq = true;
        }
    }

    /**
     * Append damage.
     */
    public void append1Hit(int damage, int poison) {
        if (damage > skillLvl[3]) {
            damage = skillLvl[3];
        }
        updateHP(damage, false);
        if (!hit1UpdateReq) {
            hitDiff1 = damage;
            poisonHit1 = poison;
            hit1UpdateReq = true;
        } else {
            hitDiff2 = damage;
            poisonHit2 = poison;
            hit2UpdateReq = true;
        }
        updateReq = true;
    }

    /**
     * Block anims.
     */
    public int getBlockAnim() {
        if (equipment[3] == 4031) {
            return 221;
        }
        if (equipment[5] == 8850) {
            return 4177;
        }
        return 1156;
    }

    /**
     * Block anims.
     */
    public int getBlockAnim1() {
        if (equipment[3] == 4031) {
            return 221;
        }
        if (equipment[3] == 4151) {
            return 1659;
        }
        if (equipment[3] == 4718 ||
                equipment[3] == -1) {
            return 424;
        }
        if (equipment[3] == 4755) {
            return 2063;
        }
        if (equipment[3] == 10887) {
            return 5866;
        }
        if (equipment[3] == 4153) {
            return 1666;
        }
        if (equipment[3] == 11694 ||
                equipment[3] == 11696 ||
                equipment[3] == 11698 ||
                equipment[3] == 11700 ||
                equipment[3] == 1307 ||
                equipment[3] == 1309 ||
                equipment[3] == 1311 ||
                equipment[3] == 1313 ||
                equipment[3] == 1315 ||
                equipment[3] == 1317 ||
                equipment[3] == 1319 ||
                equipment[3] == 7158 ||
                equipment[3] == 11730) {
            return 7050;
        }
        if (equipment[3] == 3204) {
            return 420;
        }
        return 404;
    }

    /**
     * Force chat text.
     */
    public void requestForceChat(String s) {
        forceChat = s;
        forceChatUpdateReq = true;
        updateReq = true;
    }

    public boolean quickChat;

    public void requestForceChat2(String s) {
        quickChat = true;
        chatTextUpdateReq = true;
        chatText = s;
        updateReq = true;
    }

    public int getArmourDef() {
        switch (equipment[4]) {

            case 1127:
                return 80;
            case 4712:
                return 120;
            case 4757:
                return 140;
            case 4720:
                return 140;
            case 3140:
                return 100;
            case 10551:
                return 70;
            case 11720:
                return 215;
            case 11724:
                return 220;
        }
        return 10;
    }

    public int getRangeArmourDef() {
        switch (equipment[4]) {

            case 1135:
                return 115;
            case 2499:
                return 140;
            case 2501:
                return 165;
            case 2503:
                return 190;
            case 11720:
                return 200;
        }
        return 40;
    }

    public int getRangeBonus() {
        switch (equipment[3]) {

            case 841:
                return 65;
            case 843:
                return 80;
            case 845:
                return 85;
            case 847:
                return 90;
            case 849:
                return 95;
            case 851:
                return 100;
            case 853:
                return 120;
            case 855:
                return 130;
            case 857:
                return 150;
            case 859:
                return 165;
            case 861:
                return 180;
            case 9185:
                return 280;
            case 11235:
                return 160;
        }
        return 60;
    }


    public boolean defile;

    public void checkVeracs() {
        if (barrowsSet(6)) {
            if (Math.random() <= 0.15) {
                defile = true;
            }
        } else {
            defile = false;
        }
    }

    public double accuracy = 1;

    public double meleeAccuracy(Player opp) {
        if (opp == null || this.isDead || opp.isDead || this.disconnected[0] || opp.disconnected[0]) {
            return 1;
        }
        double attack = skillLvl[0];
        double defence = opp.skillLvl[1];
        int activeAttackBonus = weaponStyle(equipment[3]) - 1;
        int activeDefenceBonus = activeAttackBonus + 5;
        double attackBonus = equipmentBonus[activeAttackBonus];
        double defenceBonus = opp.equipmentBonus[activeDefenceBonus];
        if (usingPrayer(2)) {
            attack *= 1.05;
        }
        if (usingPrayer(7)) {
            attack *= 1.10;
        }
        if (usingPrayer(15)) {
            attack *= 1.15;
        }
        if (usingPrayer(25)) {
            attack *= 1.29;
        }
        if (usingPrayer(26)) {
            attack *= 1.20;
        }
        if (attackStyle() == 4) {
            attack += 1;
        }
        if (attackStyle() == 1) {
            attack += 3;
        }
        if (opp.usingPrayer(0)) {
            defence *= 1.05;
        }
        if (opp.usingPrayer(5)) {
            defence *= 1.10;
        }
        if (opp.usingPrayer(13)) {
            defence *= 1.15;
        }
        if (opp.usingPrayer(25)) {
            defence *= 1.29;
        }
        if (opp.usingPrayer(26)) {
            defence *= 1.25;
        }
        if (opp.attackStyle() == 4) {
            defence += 1;
        }
        if (opp.attackStyle() == 3) {
            defence += 3;
        }
        if (attackBonus < 0) {
            attackBonus = 0;
        }
        if (defenceBonus < 0) {
            defenceBonus = 0;
        }
        if (defile) {
            defenceBonus = 0;
        }
        double offensiveAttribute = (attack * 1.5) + attackBonus;
        double defensiveAttribute = (defence * 1.5) + defenceBonus;
        double difference = Math.abs(offensiveAttribute - defensiveAttribute);
        boolean positive = offensiveAttribute > defensiveAttribute;
        double interval = difference * 0.0015;
        double percentage = 0.55;
        if (!positive) {
            percentage -= interval;
        }
        if (positive) {
            percentage += interval;
        }
        if (accuracy != 1) {
            percentage *= accuracy;
            accuracy = 1;
        }
        return percentage;
    }

    public boolean hitPlayer(Player opp) {
        return Math.random() <= meleeAccuracy(opp);
    }

    public double rangeAccuracy(Player opp) {
        if (opp == null || this.isDead || opp.isDead || this.disconnected[0] || opp.disconnected[0]) {
            return 1;
        }
        double range = skillLvl[4];
        double defence = opp.skillLvl[1];
        double rangeBonus = equipmentBonus[4];
        double defenceBonus = opp.equipmentBonus[9];
        if (usingPrayer(3)) {
            range *= 1.05;
        }
        if (usingPrayer(11)) {
            range *= 1.10;
        }
        if (usingPrayer(20)) {
            range *= 1.15;
        }
        if (attackStyle() == 5) {
            range += 1;
        }
        if (opp.usingPrayer(0)) {
            defence *= 1.05;
        }
        if (opp.usingPrayer(5)) {
            defence *= 1.10;
        }
        if (opp.usingPrayer(13)) {
            defence *= 1.15;
        }
        if (opp.usingPrayer(25)) {
            defence *= 1.29;
        }
        if (opp.usingPrayer(26)) {
            defence *= 1.25;
        }
        if (opp.attackStyle() == 4) {
            defence += 1;
        }
        if (opp.attackStyle() == 3) {
            defence += 3;
        }
        if (rangeBonus < 0) {
            rangeBonus = 0;
        }
        if (defenceBonus < 0) {
            defenceBonus = 0;
        }
        double offensiveAttribute = range + rangeBonus;
        double defensiveAttribute = defence + defenceBonus;
        double difference = Math.abs(offensiveAttribute - defensiveAttribute);
        boolean positive = offensiveAttribute > defensiveAttribute;
        double interval = difference * 0.00175;
        double percentage = 0.50;
        if (!positive) {
            percentage -= interval;
        }
        if (positive) {
            percentage += interval;
        }
        if (accuracy != 1) {
            percentage *= accuracy;
            accuracy = 1;
        }
        return percentage;
    }

    public boolean hitPlayerRange(Player opp) {
        return Math.random() <= rangeAccuracy(opp);
    }

    public boolean barrowsSet(int setID) {
        String helmet = Engine.items.getItemName(equipment[0]);
        String platebody = Engine.items.getItemName(equipment[4]);
        String weapon = Engine.items.getItemName(equipment[3]);
        String platelegs = Engine.items.getItemName(equipment[7]);
        String set = "";
        switch (setID) {
            case 1:    //Ahrim's
                set = "Ahrim";
                break;
            case 2: //Dharok's
                set = "Dharok";
                break;
            case 3: //Guthan's
                set = "Guthan";
                break;
            case 4: //Karil's
                set = "Karil";
                break;
            case 5: //Torag's
                set = "Torag";
                break;
            case 6: //Verac's
                set = "Verac";
                break;
        }
        boolean hasHelmet = helmet.contains(set);
        boolean hasPlatebody = platebody.contains(set);
        boolean hasWeapon = weapon.contains(set);
        boolean hasPlatelegs = platelegs.contains(set);
        if (hasHelmet && hasPlatebody && hasWeapon && hasPlatelegs) {
            return true;
        }
        return false;
    }

    public boolean voidSet(int setID) {
        String helmet = Engine.items.getItemName(equipment[0]);
        String set = "";
        switch (setID) {
            case 1: //Melee
                set = "Void melee";
                break;
            case 2: //Range
                set = "Void ranger";
                break;
            case 3: //Mage
                set = "Void mage";
                break;
        }
        boolean hasHelmet = helmet.contains(set);
        boolean hasTop = equipment[4] == 8839;
        boolean hasGloves = equipment[9] == 8842;
        boolean hasBottom = equipment[7] == 8840;
        if (hasHelmet && hasTop && hasGloves && hasBottom) {
            return true;
        }
        return false;
    }

    public boolean hasProperArrows(int bow, int arrows) {
        if (usingSpecial) {
            if (weapon == 861 || weapon == 11235) {
                if (equipmentN[13] <= 1) {
                    actionSender.sendMessage(this, "You don't have enough ammo!");
                    return false;
                }
            }
        }
        if (bow >= 839 && bow <= 861) {
            switch (arrows) {
                case 882:
                case 884:
                case 886:
                case 888:
                case 890:
                case 892:
                    return true;
            }
        }
        if (bow == 11235) {
            switch (arrows) {
                case 882:
                case 884:
                case 886:
                case 888:
                case 890:
                case 892:
                case 11212:
                    if (equipmentN[13] > 1) {
                        return true;
                    } else {
                        actionSender.sendMessage(this, "You don't have enough ammo!");
                        return false;
                    }
            }
        }
        if (bow == 4214 || bow == 868 || bow == 11230) {
            return true;
        }
        if (bow == 9185) {
            switch (arrows) {
                case 9243:
                case 9244:
                    return true;
            }
        }
        if (bow == 4734) {
            if (arrows == 4740) return true;
        }
        return false;
    }

    public boolean hitNpcRange() {
        PlayerCombat playCb = new PlayerCombat(this);
        if (getRandom(equipmentBonus[8] + getRangeBonus()) > getRandom(playCb.getNpcDefenceRange())) {
            return true;
        }
        return false;
    }

    private int getRandom(int range) {
        return (int) (Math.random() * (range + 1));
    }

    /**
     * Gives experience to a player.
     *
     * @param amount  The amount which will gives to the player
     * @param skillId the skill Id of the player which the exp will go to.
     */
    public void appendExperience(int amount, int skillId) {
        if (!gainCombatXP &&
                ((skillId == 0) || (skillId == 1) || (skillId == 2) || (skillId == 3) || (skillId == 4) || (skillId == 5)
                        || (skillId == 6))) {
            return;
        }
        int oldLvl = getLevelForXP(skillId);
        if (skillXP[skillId] > 200000000) {
            return;
        }
        skillXP[skillId] += amount;
        int newLvl = getLevelForXP(skillId);
        if (oldLvl < newLvl) {
            skillLvl[skillId] += (newLvl - oldLvl);
            sendLevelup(skillId);
            requestGFX(1635, 0);
            //requestGFX(199,100);
            appearanceUpdateReq = true;
            updateReq = true;
        }
        actionSender.setSkillLvl(this, skillId);
    }

    public void sendLevelup(int skillID) {
        dialogueId = 0;
        dialogueOptionsId = 0; // These allow the dialogue to close when they click
        // "Click here to continue" - Default action is to close ;)
        actionSender.sendMessage(this, "You've just advanced a " + Misc.getSkillName(skillID) + " level! You have " +
                "reached level " + getLevelForXP(skillID) + ".");
        actionSender.setString(this, "Congratulations, you have just advanced a " + Misc.getSkillName(skillID)
                + " level!", 740, 0);
        actionSender.setString(this, "You have now reached level " + getLevelForXP(skillID) + "!", 740, 1);
        //actionSender.setConfig(this, 1179, Misc.getFlashingIcon(skillID));
        actionSender.showChatboxInterface(this, 740);
    }

    public long lastItemUsed = 0; // Timer for ItemOnItem

    /**
     * Checks special amount and gets config.
     */
    public void checkAmount() {
        int amount = specAmount;
        actionSender.setConfig2(this, 300, amount);
    }

    /**
     * Walking request.
     */
    public void playerWalk(int x, int y, int emote, int delay) {
        int firstX = x - (mapRegionX - 6) * 8;
        int firstY = y - (mapRegionY - 6) * 8;
        Engine.playerMovement.resetWalkingQueue(this);
        Engine.playerMovement.addToWalkingQueue(this, firstX, firstY);
        appearanceUpdateReq = true;
        updateReq = true;
    }

    public boolean inWilderness() {
        return absX >= 3136 && absX <= 3350 && absY >= 3523 && absY <= 3597;
    }

    /**
     * Cross wilderness ditch
     */
    public void crossDitch() {
        int y = 3520;
        if (!wildernessZone(absX, absY)) {
            y = 3523;
        }
        playerWalk(absX, y, 6132, 0);
        appearanceUpdateReq = true;
        updateReq = true;
    }

    public boolean mattiscool = false;

    /**
     * Boolean which returns coords ids to get safezone of bounty hunter place.
     */


    public boolean pkArenaPart1() {
        return absX >= 3136 && absX <= 3192 && absY >= 3651 && absY <= 3701;
    }


    public boolean pkArenaPart2() {
        return absX >= 3136 && absX <= 3192 && absY >= 3651 && absY <= 3701;
    }

    public boolean inPkArena() {
        return pkArenaPart1() && pkArenaPart2();
    }

    void updateStats() {
        if (isDead) {
            return;
        }
        int skill = 0;
        while (skill <= 22) {
            if (skill == 3 || skill == 5) {
                skill++;
            }
            if (skillLvl[skill] > getLevelForXP(skill)) {
                skillLvl[skill]--;
            }
            if (skillLvl[skill] < getLevelForXP(skill)) {
                skillLvl[skill]++;
            }
            statDelay = 100;
            actionSender.setSkillLvl(this, skill);
            skill++;
        }
    }

    void restoreHP() {
        if (isDead) {
            return;
        }
        if (skillLvl[3] > getLevelForXP(3)) {
            skillLvl[3]--;
        }
        if (skillLvl[3] < getLevelForXP(3)) {
            skillLvl[3] += equipment[9] == 11133 ? 2 : 1;
        }
        hpDelay = 100;
        actionSender.setSkillLvl(this, 3);
    }

    /**
     * Unequip and delete all items player has.
     */
    public void dropAllStuff() {
        if (this == null)
            return;
        PlayerItems pi = new PlayerItems();
        for (int i = 0; i < items.length; i++) {
            if (items[i] == 6570)
                break;
            if (items[i] >= 0) {
                if (Engine.items.isUntradable((items[i]))) {
                    Engine.playerItems.deleteItem(this, items[i], pi.getItemSlot(this, items[i]), itemsN[i]);
                } else {
                    Engine.playerItems.deleteItem(this, items[i], pi.getItemSlot(this, items[i]), itemsN[i]);
                }
            }
        }
        for (int i = 0; i < equipment.length; i++) {
            if (equipment[i] == 6570)
                break;
            if (equipment[i] >= 0) {
                actionSender.removeEquipment(this, equipment[i], i);
                if (Engine.items.isUntradable((items[0]))) {
                    Engine.playerItems.deleteItem(this, items[0], pi.getItemSlot(this, items[0]), itemsN[0]);

                } else {
                    Engine.playerItems.deleteItem(this, items[0], pi.getItemSlot(this, items[0]), itemsN[0]);
                }
            }
        }
        combatType = 0;
    }

    public boolean arrayContains(int[] array, int value) {
        for (int i : array) {
            if (value == i) {
                return true;
            }
        }
        return false;
    }

    public int[] removeValueFromArray(int[] array, int value) {
        int index = -1;
        for (int i = 0; i < array.length; i++) {
            if (value == array[i]) {
                index = i;
            }
        }
        if (index != -1) {
            array[index] = 0;
        }
        return array;
    }

    public int[][] removeValueFromArray(int[][] array, int value) {
        int indexI = -1;
        int indexJ = -1;
        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array[i].length; j++) {
                if (value == array[i][j]) {
                    indexI = i;
                    indexJ = j;
                }
            }
        }
        if (indexI != -1 && indexJ != -1) {
            array[indexI][indexJ] = -1;
        }
        return array;
    }

    /**
     * This ensures when staff does ::kill, the player doesn't lose stuff
     */
    public boolean dontDrop = false;
    
    void dropStuff(String opp) {
        if (!wildernessZone(absX, absY)) {
            if (this.rights > 0 || this.donor || dontDrop) {
                if (dontDrop) {
                    dontDrop = false;
                }
            return;
            }
        }
        try {
            int amountOfKeptItems = isSkulled ? (usingPrayer(10) ? 1 : 0) : (usingPrayer(10) ? 4 : 3);
            int[] allItems = new int[items.length + equipment.length];
            int[] allItemsN = new int[itemsN.length + equipmentN.length];
            int[] keptItems = new int[amountOfKeptItems];
            int[] toAdd = new int[keptItems.length];
            System.arraycopy(items, 0, allItems, 0, items.length);
            System.arraycopy(equipment, 0, allItems, items.length, equipment.length);
            System.arraycopy(itemsN, 0, allItemsN, 0, itemsN.length);
            System.arraycopy(equipmentN, 0, allItemsN, itemsN.length, equipmentN.length);
            for (int i = 0; i < keptItems.length; i++) {
                int index = 0;
                int standing = 0;
                for (int j = 0; j < allItems.length; j++) {
                    if (allItems[j] < 1) {
                        continue;
                    }
                    int price = Engine.items.itemLists[allItems[j]].shopValue;
                    if (price > standing) {
                        index = j;
                        standing = price;
                    }
                }
                keptItems[i] = allItems[index];
                toAdd[i] = allItems[index];
                allItemsN[index]--;
                if (allItemsN[index] == 0) {
                    allItems[index] = 0;
                }
            }
            for (int i = 0; i < items.length; i++) {
                if (items[i] > 0) {
                    if (!arrayContains(keptItems, items[i])) {
                        if (Engine.items.isUntradable((items[i]))) {
                            if (items[i] != 13290) {
                                Engine.items.createGroundItem(items[i], itemsN[i], absX, absY, heightLevel, username);
                            } else {
                                actionSender.sendMessage(this, "Your Vesta's longsword shatters as it hits the ground.");
                                degrade = 6000;
                                degrades = false;
                            }
                            Engine.playerItems.deleteItem(this, items[i], Engine.playerItems.getItemSlot(this, items[i]), itemsN[i]);
                        } else {
                            Engine.items.createGroundItem(items[i], itemsN[i], absX, absY, heightLevel, opp);
                        }
                    } else {
                        keptItems = removeValueFromArray(keptItems, items[i]);
                    }
                    Engine.playerItems.deleteItem(this, items[i], Engine.playerItems.getItemSlot(this, items[i]), itemsN[i]);
                }
            }
            for (int i = 0; i < equipment.length; i++) {
                if (equipment[i] > 0) {
                    actionSender.removeEquipment(this, equipment[i], i);
                    if (!arrayContains(keptItems, items[0])) {
                        if (Engine.items.isUntradable((items[0]))) {
                            if (items[0] != 13290) {
                                Engine.items.createGroundItem(items[0], itemsN[0], absX, absY, heightLevel, username);
                            } else {
                                actionSender.sendMessage(this, "Your Vesta's longsword shatters as it hits the ground.");
                                degrade = 6000;
                                degrades = false;
                            }
                            Engine.playerItems.deleteItem(this, items[0], Engine.playerItems.getItemSlot(this, items[0]), itemsN[0]);
                        } else {
                            Engine.items.createGroundItem(items[0], itemsN[0], absX, absY, heightLevel, opp);
                        }
                    } else {
                        keptItems = removeValueFromArray(keptItems, items[0]);
                    }
                    Engine.playerItems.deleteItem(this, items[0], Engine.playerItems.getItemSlot(this, items[0]), itemsN[0]);
                }
            }
            for (int i : toAdd) {
                if (i > 0) {
                    Engine.playerItems.addItem(this, i, 1);
                }
            }
            Engine.items.createGroundItem(995, 500, absX, absY, heightLevel, opp);
            Engine.items.createGroundItem(526, 1, absX, absY, heightLevel, opp);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("Null drop: " + opp);
            return;
        }
    }

    public int totalValue(int[] items) {
        int totalValue = 0;
        try {
            int[] allItems = new int[items.length + equipment.length];
            System.arraycopy(items, 0, allItems, 0, items.length);
            System.arraycopy(equipment, 0, allItems, items.length, equipment.length);

            for (int i : allItems) {
                totalValue += getItemValue(i);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
        return totalValue;
    }


    void PVPDrop(String player, int[] lostItems) {
        Player dropFor = Engine.players[Engine.getIdFromName(player)];
        try {
            if (dropFor.setDrop != 0) {
                Engine.items.createGroundItem(dropFor.setDrop, 1, absX, absY, heightLevel, player);
                dropFor.setDrop = 0;
            }
            if (Double.isInfinite(dropFor.PVPPotential) || Double.isNaN(dropFor.PVPPotential)) {
                dropFor.PVPPotential = 0.0;
            }
            double chance = 0.00;
            int randomDrops = 0;
            for (int i : lostItems) {
                if (Math.random() <= 0.75) {
                    lostItems = removeValueFromArray(lostItems, i);
                } else {
                    if (getItemValue(i) >= 3000) {
                        randomDrops++;
                    } else if (Math.random() <= 0.25) {
                        randomDrops++;
                    }
                }

            }
            for (int i : lostItems) {
                if (i == 0 || Engine.items.isUntradable(i)) {
                    continue;
                }
                Engine.items.createGroundItem(i, 1, absX, absY, heightLevel, player);
            }
            int[] targetDrops = {13902, 11694, 6585, 11696, 11724, 11726, 11732};
            int[] potentialDrops = pvpItemsDrops;
            for (int i = 0; i < randomDrops; i++) {
                int item = potentialDrops[(int) Math.floor(Math.random() * potentialDrops.length)];
                chance = getPVPDropPercentage(item, totalValue(lostItems), dropFor.PVPPotential);
                if (Math.random() <= chance) {
                    Engine.items.createGroundItem(item, 1, absX, absY, heightLevel, player);
                    dropFor.PVPPotential -= ((1.00 - chance) / 10);
                } else {
                    dropFor.PVPPotential += ((1.00 - chance) / 10);
                }
            }
        } catch (Exception e) {
        }
    }

    double getPVPDropPercentage(int item, int risk, double potential) {
        double base = 0.10 + potential * (hotZone(absX, absY) ? 3.00 : 1.50);
        double ratio = getItemValue(item) / 1457000;
        double value = base / ratio;
        if (value > 0.95) {
            value = 0.95;
        }
        return value;
    }

    void drainPrayer() {
        if (usingPrayer) {
            if (drainDelay == 0) {
                if (skillLvl[5] <= 1) {
                    resetPrayer();
                    skillLvl[5]--;
                    actionSender.setSkillLvl(this, 5);
                    appearanceUpdateReq = true;
                    updateReq = true;
                    actionSender.sendMessage(this, "You are out of prayer points. Please restore them at an prayer altar.");
                    return;
                }
                skillLvl[5]--;
                actionSender.setSkillLvl(this, 5);
            }
            drainDelay = 8;
            appearanceUpdateReq = true;
            updateReq = true;
        }
    }

    public void appendWilderness() {
        wildyLevel = getWildernessLevel();
        if (savedLevel != wildyLevel) {
            savedLevel = wildyLevel;
            if (wildyLevel > 0) {
                addWilderness();
            } else {
                removeWilderness();
            }
        }
    }

    public boolean removedWildy;

    public void removeWilderness() {
        actionSender.setPlayerOption(this, "Null", 1, true);
        actionSender.removeOverlay(this);
        actionSender.setInterfaceConfig(this, 745, 6, true);
        actionSender.setInterfaceConfig(this, 745, 3, false);
        removedWildy = true;
    }

    public void addSnow() {
        this.actionSender.setOverlay(this, 370);
    }

    public void removeSnow() {
        this.actionSender.removeOverlay(this);
    }

    public void addWilderness() {
        removedWildy = false;
        actionSender.setPlayerOption(this, "Attack", 1, true);
        if (!isPVP()) {
            //actionSender.setOverlay(this, 381);
        } else {
            actionSender.setInterfaceConfig(this, 745, 6, false);
            actionSender.setInterfaceConfig(this, 745, 3, true);
            int max = combatLevel + wildyLevel;
            if (max > 126) {
                max = 126;
            }
            int min = (combatLevel - wildyLevel) + (((combatLevel % 10 >= 5) && ((combatLevel - wildyLevel) % 10 < 5) || (combatLevel >= 114)) ? 2 : 1);
            if (min < 3) {
                min = 3;
            }
            String range = min + " - " + max;
            ;
        }
    }

    public int wildernessLevels(int coordY) {
        wildyLevel = (coordY - 3254 / 7);
        if (wildyLevel < 1)
            wildyLevel = 1;
        return wildyLevel;
    }

    public boolean inEdge() {
        return absX >= 3040 && absX <= 3125 && absY >= 3523 && absY <= 3551;
    }

    /**
     * Dharok's equipment check.
     */
    public boolean fullDharok() {
        return equipment[3] == 4718 && equipment[4] == 4720 && equipment[7] == 4722 && equipment[0] == 4716;
    }

    /**
     * Verac's equipment check.
     */
    public boolean fullVerac() {
        return equipment[3] == 4755 && equipment[4] == 4757 && equipment[7] == 4759 && equipment[0] == 4753;
    }

    /**
     * Guthan equipment chck
     */
    public boolean hasGuthanEquipment() {
        return equipment[3] == 4726 && equipment[4] == 4728 && equipment[7] == 4730 && equipment[0] == 4724;
    }

    /**
     * Safezone.
     */
    public boolean inClan() {
        return absX >= 3264 && absY >= 3672 && absX <= 3279 && absY <= 3695;
    }

    /**
     * clan wars arena
     */
    public boolean inClanFight() {
        return absX >= 3258 && absY >= 3710 && absX <= 3330 && absY <= 3842;
    }

    public int distanceToPoint(int pointX, int pointY) {
        return (int) Math.sqrt(Math.pow(absX - pointX, 2) + Math.pow(absY - pointY, 2));
    }

    public boolean fullVoidKnightRange() {
        return equipment[0] == 11675 && equipment[4] == 8839 && equipment[7] == 8840;
    }

    public boolean fullArmadyl() {
        return equipment[0] == 11718 && equipment[4] == 11720 && equipment[7] == 11722;
    }

    public boolean saraChamber() {
        return absX >= 2889 && absX <= 2907 && absY >= 5258 && absY <= 5276;
    }

    public boolean zammyChamber() {
        return absX >= 2919 && absX <= 2935 && absY >= 5319 && absY <= 5330;
    }

    public boolean graardorChamber() {
        return absX >= 2864 && absX <= 2876 && absY >= 5351 && absY <= 5369;
    }

    public boolean armadylChamber() {
        return absX >= 2823 && absX <= 2843 && absY >= 5295 && absY <= 5310;
    }

    public boolean armadylChamber1() {
        return absX >= 2825 && absX <= 2841 && absY >= 5297 && absY <= 5307;
    }

    public boolean inMageArena() {
        return absX >= 3079 && absX <= 3126 && absY >= 3906 && absY <= 3951;
    }

    public boolean inDuelArena() {
        return absX >= 3349 && absX <= 3388 && absY >= 3262 && absY <= 3280;
    }

    public boolean godWarsDung() {
        return absX >= 2828 && absX <= 2910 && absY >= 5262 && absY <= 5342;
    }
	public boolean inJadCave() {
        return absX >= 2375 && absX <= 2425 && absY >= 5128 && absY <= 5169;
    }

    /**
     * Sets the strings for kill counts for god wars dungeon.
     */
    public void setGodWarsStrings() {
        if (zammyChamber() || addZamorakCheckEventGodWars())
            for (int i = 7; i < 11; i++)
                for (int k = 0; k < 5; k++)
                    if (this != null)
                        actionSender.setString(this, "" + godWarsKills[k] + "", 598, i);
                    else
                        for (int s = 7; s < 11; s++)
                            for (int d = 0; d < 5; d++)
                                if (this != null)
                                    actionSender.setString(this, "" + godWarsKills[d] + "", 601, s);
    }

    public ActionSender actionSender = Engine.actionSender;

    public ActionSender getActionSender() {
        return Engine.actionSender;
    }

    public void setItems(int interfaceId, int childId, int type, int[] itemArray, int[] itemAmt) {
        if (this == null || stream == null || disconnected[0]) {
            return;
        }
        getByteVector().createFrameVarSizeWord(255);
        getByteVector().writeWord(interfaceId);
        getByteVector().writeWord(childId);
        getByteVector().writeWord(type);
        getByteVector().writeWord(itemArray.length);
        for (int i = 0; i < itemArray.length; i++) {
            if (itemAmt[i] > 254) {
                getByteVector().writeByteS(255);
                getByteVector().writeDWord_v2(itemAmt[i]);
            } else {
                getByteVector().writeByteS(itemAmt[i]);
            }
            getByteVector().writeWordBigEndian(itemArray[i] + 1);
        }
        getByteVector().endFrameVarSizeWord();
    }

    public QuestDevelopment getQuestClass() {
        return quest;
    }

    public Startup getStartup() {
        return startup;
    }

    public ByteVector getByteVector() {
        return stream;
    }

    public boolean duelFight() {
        return absX >= 3361 && absX <= 3392 && absY >= 3223 && absY <= 3241;
    }

    public boolean slayerTower() {
        return absX >= 3402 && absX <= 3458 && absY >= 3529 && absY <= 3581;
    }

    public void appendPotion() {
        if (explodeDelay == 0) {
            if (explodeType == 1) {
                appendHit(25, 0);
                requestForceChat("Ow!");
                actionSender.sendMessage(this, "The unidentified liquid potion exploded!");
            }
            explodeType = 0;
            explodeDelay = -1;
        }
    }

    public boolean castleLobby() {
        return absX >= 2435 && absX <= 2449 && absY >= 3079 && absY <= 3099;
    }

    public boolean castleArea() {
        return absX >= 2358 && absX <= 2438 && absY >= 3066 && absY <= 3142;
    }

    public boolean correctDistance(int j, int k, int l, int i1, int j1) {
        for (int k1 = 0; k1 <= j1; k1++) {
            for (int l1 = 0; l1 <= j1; l1++) {
                if (j + k1 == l && (k + l1 == i1 || k - l1 == i1 || k == i1))
                    return true;
                if (j - k1 == l && (k + l1 == i1 || k - l1 == i1 || k == i1))
                    return true;
                if (j == l && (k + l1 == i1 || k - l1 == i1 || k == i1))
                    return true;
            }

        }

        return false;
    }

    public int getLoginSpecial() {
        if (specAmount <= 0) {
            return 0;
        } else {
            return specAmount;
        }
    }

    public int getLoginSpellbook() {
        if (spellbook <= 0) {
            return 192;
        } else {
            return spellbook;
        }
    }

    /**
     * Edgeville 1 V 1
     */
    public boolean inEdgePk() {
        return absX >= 3040 && absX <= 3118 && absY >= 3522 && absY <= 3553;
    }

    /**
     * Checking if combat level difference is correct for attacking in wild.
     */
    public boolean combatDifference(int cbLvl) {
        return wildLevel >= combatLevel && combatLevel + cbLvl >= wildLevel || cbLvl < combatLevel && combatLevel - wildLevel <= cbLvl || cbLvl == combatLevel;
    }

    /**
     * Update the wilderness levels.
     */
    void addWildernessUpdating() {
        //actionSender.setString(this, "Level: "+getWildernessLevel(), 380, 1);
        if (updatedLevel != wildernessZone(absX, absY)) {
            updatedLevel = wildernessZone(absX, absY);
            if (updatedLevel && !inClan() && !clanWarsFightArea()) {
                //actionSender.setOverlay(this, 380);
            } else {
                wildyLevel = 0;
                actionSender.removeOverlay(this);
            }
        }
    }

    public String getMessageString(int economyId) {
        switch (economyId) {

            case 4153:
                return "Granite mauls are now disabled, Please kill Gargoyles in the Slayer tower.";

            case 4151:
            case 11235:
                return "Abyssal whips and Dark bows are disabled, Please go to Slayer tower.";

            case 2440:
            case 2434:
            case 6685:
                return "You cannot spawn the super strength potion, Prayer potion and Brews anymore, Please steal potions from the stalls at home.";

            case 385:
            case 391:
                return "You cannot spawn food anymore, Please steal food from the stalls at home.";

            case 10581:
                return "Please go to the Slayer Tower for a Keris dagger.";

            case 11690:
            case 11702:
            case 11704:
            case 11706:
            case 11708:
                return "You can only get a God hilt or Godsword blade by Defeating the Generals of the Gods in the God wars Dungeon.";

            case 11718:
            case 11720:
            case 11722:
            case 12670:
            case 12671:
                return "You can only get a piece of Armadyl armour by Visitting Armadyl's Eyrie in the Godwars dungeon.";

            case 11724:
            case 11726:
            case 11728:
                return "You can only get a piece of Bandos armour by Visitting Bandos's Stronghold in the Godwars dungeon.";

            case 3140:
                return "You can only get a Dragon chainbody by Killing the Kalphite Queen in her Kalphite Lair.";

            case 6570:
            case 10566:
            case 10637:
                return "Please visit The fight cave for a Fire cape.";

            case 11694:
            case 11696:
            case 11698:
            case 11700:
                return "Please visit the Godwars dungeon to get this item.";

            default:
                return "";
        }
    }

    public boolean newPlayer() {
        for (int i = 0; i < 24; i++) {
            if (i == 3)
                continue;
            if (getLevelForXP(i) != 1) {
                return false;
            }
        }
        return true;
    }

    /**
     * Loads objects at Map region loading.
     */
    public void loadStaticObjects() {


        //start fishing
	    actionSender.addObject(this, 2031, 0, 2604, 3417, 0, 10);//shrimps
	    actionSender.addObject(this, 8986, 0, 2607, 3416, 0, 10);//sardine
	    actionSender.addObject(this, 3032, 0, 2612, 3415, 0, 10);//herring
	    actionSender.addObject(this, 2028, 0, 2607, 3413, 0, 10);//salmon
	    actionSender.addObject(this, 2029, 0, 2602, 3413, 0, 10);//lobster
	    actionSender.addObject(this, 2030, 0, 2605, 3410, 0, 10);//shark
		//end fishin
		actionSender.addObject(this, 4469, 0, 3136, 3640, -1, 10); // Energy Barrier
		actionSender.addObject(this, 4469, 0, 3135, 3640, -1, 10); // Energy Barrier
		actionSender.addObject(this, 4469, 0, 3135, 3613, -1, 10); // Energy Barrier
		actionSender.addObject(this, 4469, 0, 3136, 3613, -1, 10); // Energy Barrier
		actionSender.addObject(this, 2561, 0, 3107, 3508, -1, 10); // lvl 1
        actionSender.addObject(this, 2560, 0, 3109, 3508, -1, 10); // Altar
        actionSender.addObject(this, 4387, 0, 2339, 3686, -1, 10); // portal
        actionSender.addObject(this, 4388, 0, 2326, 3645, -1, 10); // portal
        actionSender.addObject(this, 4388, 0, 2400, 5165, -1, 10); // portal
        actionSender.addObject(this, 4388, 0, 1888, 5393, -1, 10); // portal
	actionSender.addObject(this, 4388, 0, 2467, 3088, 1, 10); // portal
	actionSender.addObject(this, 15997, 0, 2446, 3091, 1, 10); // portal
actionSender.addObject(this, 15997, 0, 2446, 3088, 1, 10); // portal
actionSender.addObject(this, 13629, 0, 2446, 3089, 3, 10); // pvp portal
actionSender.addObject(this, 13633, 0, 3185, 3441, 4, 10); // home portal
actionSender.addObject(this, 10551, 0, 3185, 3447, 3, 10); // pvp flag
actionSender.addObject(this, 10552, 0, 3188, 3447, 3, 10); // pvp flag 2
actionSender.addObject(this, 36925, 0, 2955, 3660, 4, 10); // pkbox flag
actionSender.addObject(this, 36925, 0, 2955, 3662, 4, 10); // pkbox flag
actionSender.addObject(this, 28093, 0, 3196, 3447, 3, 10); // barrier (pvp)(ge pillar)
actionSender.addObject(this, 28093, 0, 3195, 3446, 1, 10); // barrier (pvp)(ge pillar)
actionSender.addObject(this, 409, 0, 3009, 3356, 1, 10); // altar

//vip
actionSender.addObject(this, 6574, 0, 2009, 4748, 0, 10); // stall
actionSender.addObject(this, 25667, 0, 2002, 4750, 1, 10); // knight
actionSender.addObject(this, 20378, 0, 2017, 4750, 3, 10); // altar
actionSender.addObject(this, 2213, 0, 2007, 4760, 0, 10); // bank booth
actionSender.addObject(this, 2213, 0, 2008, 4760, 0, 10); // bank booth
actionSender.addObject(this, 2213, 0, 2009, 4760, 0, 10); // bank booth
actionSender.addObject(this, 2213, 0, 2010, 4760, 0, 10); // bank booth
actionSender.addObject(this, 2213, 0, 2011, 4760, 0, 10); // bank booth
actionSender.addObject(this, 2213, 0, 2012, 4760, 0, 10); // bank booth
actionSender.addObject(this, 20288, 0, 2008, 4762, 3, 10); // body
actionSender.addObject(this, 19337, 0, 2006, 4749, 2, 10); // rabbit hole


//New player start
actionSender.addObject(this, 7353, 0, 2904, 5470, 0, 10); // Portal
actionSender.addObject(this, 7353, 0, 2913, 5464, 0, 10); // Portal
actionSender.addObject(this, 7353, 0, 2919, 5473, 0, 10); // Portal
actionSender.addObject(this, 7353, 0, 2910, 5479, 0, 10); // Portal

actionSender.addObject(this, 1306, 0, 2908, 5467, 4, 10); // tree
actionSender.addObject(this, 1306, 0, 2917, 5466, 1, 10); // tree
actionSender.addObject(this, 1306, 0, 2915, 5470, 2, 10); // tree
actionSender.addObject(this, 1306, 0, 2909, 5475, 2, 10); // tree
actionSender.addObject(this, 1306, 0, 2915, 5477, 3, 10); // tree
//End new player start
actionSender.addObject(this, 13633, 0, 3017, 3355, 3, 10); // homeprtl
        actionSender.addObject(this, 7289, 0, 2851, 2957, -1, 10); // funpk portal
       actionSender.addObject(this, 2213, 0, 2725, 3487, 0, 10); // Bank Booth
       actionSender.addObject(this, 2213, 0, 2726, 3487, 0, 10); // Bank Booth
       actionSender.addObject(this, 2213, 0, 3233, 2900, 0, 10); // Bank Booth
       actionSender.addObject(this, 2213, 0, 3232, 2900, 0, 10); // Bank Booth
       actionSender.addObject(this, 4483, 0, 2332, 3685, 0, 10); // Bank chest
       actionSender.addObject(this, 4483, 0, 2578, 2846, 2, 10); // Bank chest
       actionSender.addObject(this, 4483, 0, 3431, 3551, -1, 10); // Bank chest
       actionSender.addObject(this, 4483, 0, 3431, 3552, -1, 10); // Bank chest
       actionSender.addObject(this, 4483, 0, 3431, 3553, -1, 10); // Bank chest
       actionSender.addObject(this, 4483, 0, 3431, 3554, -1, 10); // Bank chest
       actionSender.addObject(this, 4483, 0, 3431, 3555, -1, 10); // Bank chest
        actionSender.addObject(this, 2562, 0, 3111, 3508, -1, 10); // lvl 1
	actionSender.addObject(this, 11402, 0, 2445, 3085, 4, 10); // homebank
actionSender.addObject(this, 11402, 0, 2444, 3085, 4, 10); // homebank
actionSender.addObject(this, 27713, 0, 2443, 3085, 0, 10); // homeswords
actionSender.addObject(this, 11402, 0, 2443, 3084, 1, 10); // homebank
actionSender.addObject(this, 11402, 0, 2443, 3083, 1, 10); // homebank
actionSender.addObject(this, 11402, 0, 2443, 3082, 1, 10); // homebank
actionSender.addObject(this, 11402, 0, 2443, 3082, 1, 10); // homebank


/*PRAYER*/
actionSender.addObject(this, 409, 0, 3048, 3498, 2, 10); //altar
actionSender.addObject(this, 409, 0, 3050, 3498, 2, 10); //altar
actionSender.addObject(this, 409, 0, 3052, 3498, 2, 10); //altar
actionSender.addObject(this, 409, 0, 3054, 3498, 2, 10); //altar
actionSender.addObject(this, 411, 0, 3050, 3483, 4, 10); //zammy altar
actionSender.addObject(this, 411, 0, 3052, 3483, 4, 10); //zammy altar
actionSender.addObject(this, 13198, 0, 3051, 3490, 4, 10); //zammy altar(gilded)
actionSender.addObject(this, 13197, 0, 3051, 3491, 2, 10); //sara altar(gilded)
actionSender.addObject(this, 13633, 0, 3059, 3490, 3, 10); // home portal
/*END PRAYER*/


        actionSender.addObject(this, 2478, 0, 2839, 4836, 0, 10); // Air altar
        actionSender.addObject(this, 2488, 0, 2846, 4831, 0, 10); // Death altar
        actionSender.addObject(this, 2480, 0, 2846, 4836, 0, 10); // Blood altar

        actionSender.addObject(this, 1276, 0, 2847, 2963, 0, 10); // Tree at Shilo
        actionSender.addObject(this, 1307, 0, 2849, 2966, 0, 10); // Maple at Shilo
        actionSender.addObject(this, 1309, 0, 2844, 2963, 0, 10); // Yew at Shilo
        actionSender.addObject(this, 1306, 0, 2862, 2957, 0, 10); // Magic at Shilo
        actionSender.addObject(this, 9368, 0, 2831, 2971, 0, 10); // barrier at bridge
        actionSender.addObject(this, 9368, 0, 2832, 2971, 0, 10); // barrier at bridge


        actionSender.addObject(this, 3815, 0, 2950, 3664, 0, 10); // Pkbox
        actionSender.addObject(this, 3815, 0, 2951, 3664, 0, 10); // Pkbox
        actionSender.addObject(this, 3815, 0, 2952, 3664, 0, 10); // Pkbox
        actionSender.addObject(this, 3815, 0, 2953, 3664, 0, 10); // Pkbox
        actionSender.addObject(this, 3815, 0, 2954, 3664, 0, 10); // Pkbox
        actionSender.addObject(this, 3815, 0, 2955, 3664, 0, 10); // Pkbox

        actionSender.addObject(this, 3815, 0, 2950, 3658, 0, 10); // Pkbox
        actionSender.addObject(this, 3815, 0, 2951, 3658, 0, 10); // Pkbox
        actionSender.addObject(this, 3815, 0, 2952, 3658, 0, 10); // Pkbox
        actionSender.addObject(this, 3815, 0, 2953, 3658, 0, 10); // Pkbox
        actionSender.addObject(this, 3815, 0, 2954, 3658, 0, 10); // Pkbox
        actionSender.addObject(this, 3815, 0, 2955, 3658, 0, 10); // Pkbox

        actionSender.addObject(this, 2213, 0, 2950, 3659, -1, 10); // Pkbox
        actionSender.addObject(this, 2213, 0, 2950, 3660, -1, 10); // Pkbox
        actionSender.addObject(this, 2213, 0, 2950, 3661, -1, 10); // Pkbox
        actionSender.addObject(this, 2213, 0, 2950, 3662, -1, 10); // Pkbox
        actionSender.addObject(this, 2213, 0, 2950, 3653, -1, 10); // Pkbox
        actionSender.addObject(this, 2213, 0, 2950, 3663, -1, 10); // Pkbox
        actionSender.addObject(this, 3815, 0, 2955, 3663, 0, 10); // Pkbox
        actionSender.addObject(this, 409, 0, 2852, 2951, 0, 10); // Altar
        actionSender.addObject(this, 409, 0, 3431, 3548, -1, 10); // Altar

        actionSender.addObject(this, 3815, 0, 2955, 3659, 0, 10); // Pkbox
        
        
        replaceDoors();
    }


    /**
     * Zammys part of god wars area check boolean
     */
    public boolean addZamorakCheckEventGodWars() {
        return absX >= 2879 && absX <= 2945 && absY >= 5342 && absY <= 5364;
    }

    /**
     * Update the player.
     */
    public void updatePlayer(boolean updateIsNeccesary) {
        appearanceUpdateReq = updateReq = updateIsNeccesary;
    }

    public int getX() {
        return absX;
    }

    public int getY() {
        return absY;
    }

    public int getHeight() {
        return heightLevel;
    }

    public int getPlayerId() {
        return playerId;
    }

    public void convertPlayerToNpc(int npcType) {
        this.npcType = npcType;
    }

    public void updatePlayerAppearance(int walkAnim, int standAnim, int runAnim) {
        standEmote = standAnim;
        walkEmote = walkAnim;
        runEmote = runAnim;
    }

    public void appendToIPBanned(Player player) {
        BufferedWriter bw = null;
        try {
            bw = new BufferedWriter(new FileWriter("./data/banned/bannedhosts.dat", true));
            bw.write(Server.socketListener.getAddress(player.socket.socket));
            bw.newLine();
            bw.flush();
            Server.socketListener.loadBannedHosts();
            player.disconnected[0] = true;
            player.disconnected[1] = true;
        } catch (IOException ioe) {
        } finally {
            if (bw != null) {
                try {
                    bw.close();
                } catch (IOException ioe2) {
                }
            }
        }
    }

    public void appendToBanned(String player) {
        BufferedWriter bw = null;
        try {
            bw = new BufferedWriter(new FileWriter("./data/banned/bannedusers.dat", true));
            bw.write(player);
            bw.newLine();
            bw.flush();
            bw.close();
            Player other = Engine.players[Engine.getIdFromName(player)];
            other.disconnected[0] = true;
            other.disconnected[1] = true;
            Server.loadBannedUsers();
        } catch (IOException ioe) {
        }
    }

    String Directory = "./data/banned/bannedusers.dat";
    String MaxBan[] = new String[50000];
    String UserThatBan = new String();
    int Ban = 0;

    public void UnBanPlayer(String Player) {
        try {
            BufferedReader dataStream = new BufferedReader(new FileReader("./data/banned/bannedusers.dat"));
            while ((UserThatBan = dataStream.readLine()) != null) {
                if (!UserThatBan.equalsIgnoreCase(Player)) {
                    MaxBan[Ban] = UserThatBan;
                    Ban++;
                }
            }
            dataStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        BufferedWriter bw = null;
        try {
            bw = new BufferedWriter(new FileWriter("./data/banned/bannedusers.dat", false));
            for (int a = 0; a < MaxBan.length; a++) {
                if (MaxBan[a] != null) {
                    bw.write(MaxBan[a]);
                    bw.newLine();
                    bw.flush();
                }
            }
            bw.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        Server.loadBannedUsers();
    }

    public boolean nonMultiPlace() {
        if (absX >= 3400 && absX <= 3457 && absY >= 3527 && absY <= 3579 && heightLevel == 2) {
            return true;
        }
        if ((absX >= 3520 && absX <= 3585 && absY >= 9659 && absY <= 9725) // BARROWS
                || (absX >= 3102 && absX <= 3130 && absY >= 9922 && absY <= 9980) // EDGE DUNG DRAGS
                ) {
            return true;
        }
        return false;
    }

    public int neededSpecialAmount() {
        switch (equipment[3]) {
            case 1215:
            case 1231:
            case 5680:
            case 5698:
            case 1305:
            case 1434:
                return 250;
            case 10887:
            case 11694:
            case 11698:
            case 4151:
            case 7449:
                return 500;
            case 11235:
                return 550;
            case 11700:
                return 600;
            case 11696:
            case 11730:
                return 1000;
            default:
                return 0;
        }
    }

    public int weaponType;

    public int attackStyle() {

        /*
           * Melee weapon styles
           * 1 : accurate
           * 2 : agressive
           * 3 : defensive
           * 4 : controlled
           *
           * Ranged weapon styles
           * 5 : accurate
           * 6 : rapid
           * 7 : longrange
           */

        switch (weaponType) {
            case 0:
                return fightStyle;
            case 1:
                return fightStyle;
            case 2:
                if (fightStyle == 1) {
                    return 1;
                }
                if (fightStyle == 3) {
                    return 2;
                }
                if (fightStyle == 2) {
                    return 3;
                }
            case 3:
                if (fightStyle == 1) {
                    return 1;
                }
                if (fightStyle == 2) {
                    return 2;
                }
                if (fightStyle == 3) {
                    return 4;
                }
                if (fightStyle == 4) {
                    return 3;
                }
            case 4:
                if (fightStyle == 1) {
                    return 5;
                }
                if (fightStyle == 3) {
                    return 6;
                }
                if (fightStyle == 2) {
                    return 7;
                }
            case 5:
                break;
            case 6:
                return fightStyle;
            case 7:
                if (fightStyle == 1) {
                    return 1;
                }
                if (fightStyle == 2 || fightStyle == 3) {
                    return 2;
                }
                if (fightStyle == 4) {
                    return 3;
                }
            case 8:
                if (fightStyle == 1) {
                    return 1;
                }
                if (fightStyle == 4 || fightStyle == 3) {
                    return 2;
                }
                if (fightStyle == 2) {
                    return 3;
                }
            case 9:
                if (fightStyle == 1) {
                    return 4;
                }
                if (fightStyle == 2) {
                    return 2;
                }
                if (fightStyle == 3) {
                    return 3;
                }
            case 10:
                if (fightStyle == 1) {
                    return 1;
                }
                if (fightStyle == 2) {
                    return 2;
                }
                if (fightStyle == 3) {
                    return 4;
                }
                if (fightStyle == 4) {
                    return 3;
                }
            case 11:
                if (fightStyle == 1) {
                    return 1;
                }
                if (fightStyle == 4) {
                    return 2;
                }
                if (fightStyle == 3) {
                    return 4;
                }
                if (fightStyle == 2) {
                    return 3;
                }
            case 12:
                if (fightStyle == 1 || fightStyle == 2) {
                    return fightStyle;
                }
                if (fightStyle == 3) {
                    return 4;
                }
                if (fightStyle == 4) {
                    return 3;
                }
        }
        return 8;
    }

    public int weaponStyle(int weaponID) {
        switch (weaponID) {
            case 4151:
                return 2;
            case 4153:
                return 3;
            case 1277:
            case 1279:
            case 1281:
            case 1283:
            case 1285:
            case 1287:
            case 1289:
            case 1291:
            case 1293:
            case 1295:
            case 1297:
            case 1299:
            case 1301:
            case 1303:
            case 1305:
            case 1329:
            case 1331:
            case 1337:
            case 4587:
                if (fightStyle != 3) {
                    return 2;
                } else {
                    return 1;
                }
            case 1434:
            case 4755:
            case 10887:
                if (fightStyle != 3) {
                    return 3;
                } else {
                    return 1;
                }
            case 1215:
            case 1231:
            case 5680:
            case 5698:
                if (fightStyle != 3) {
                    return 1;
                } else {
                    return 2;
                }
            case 1307:
            case 1309:
            case 1311:
            case 1313:
            case 1315:
            case 1317:
            case 1319:
            case 1349:
            case 1351:
            case 1353:
            case 1355:
            case 1357:
            case 1359:
            case 1361:
            case 1363:
            case 1365:
            case 1367:
            case 1369:
            case 1371:
            case 1373:
            case 1375:
            case 1377:
            case 4718:
            case 6739:
            case 7158:
            case 7449:
            case 11694:
            case 11696:
            case 11698:
            case 11700:
            case 11730:
                if (fightStyle != 3) {
                    return 2;
                } else {
                    return 3;
                }
        }
        return 1;
    }

    public int getAttackSound() {
        String weapon = Engine.items.getItemName(equipment[3]);
        if (weapon.equals("Abyssal whip")) {
            return 2720;
        }
        if (weapon.contains("godsword") || weapon.equals("Saradomin sword")) {
            switch (fightStyle) {
                case 1:
                case 2:
                case 4:
                    return 3846;
                case 3:
                    return 3882;
            }
        }
        if (weapon.equals("Granite maul")) {
            return 2714;
        }
        return -1;
    }

    public int getSpecialAttackSound() {
        return -1;
    }

    public boolean clanWarsFightArea() {
        return absX >= 3263 && absX <= 3327 && absY >= 3713 && absY <= 3840;
    }

    /**
     * Prepare player for removal.
     */
    public void destruct() {
        stream = null;
        try {
//	    removewhat();
            socket.input.close();
            socket.output.close();
            socket.socket.close();
            Server.socketListener.connectionsList.remove(Server.socketListener.getAddress(this.socket.socket));
        } catch (Exception e) {
        }
        long me = Misc.stringToLong(username);
        for (Player p : Engine.players) {
            if (p == null) continue;
            //if (p3.target == player) {
            //		p3.
            if (p.friends.contains(me)) {
                p.actionSender.sendFriend(p, me, 0);
            }
        }
        socket.input = null;
        socket.output = null;
        socket.socket = null;
        socket = null;
        absX = absY = mapRegionX = mapRegionY = -1;
    }

    public static int barrowsItems[] = {4708, 4710, 4712, 4714, 4716, 4718, 4720, 4722, 4724, 4726,
            4728, 4730, 4732, 4734, 4736, 4738, 4745, 4747, 4749, 4751, 4753, 4755, 4757, 4759};

    public static int getBarrowsReward() {
        return barrowsItems[(int) (Math.random() * barrowsItems.length)];
    }

    public boolean restrictedAttack(int npcId) {
        int npcType = Engine.npcs[npcId].npcType;
        switch (npcType) {
            case 6222: // Armadyl boss
                if (absX < 2824 || absY < 5296 || absX > 2842 || absY > 5308) {
                    message("You can't attack the boss outside of the room.");
                    return true;
                }
                break;
            case 6247: // Saradomin boss
                if (absX < 2889 || absY < 5258 || absX > 2907 || absY > 5276) {
                    message("You can't attack the boss outside of the room.");
                    return true;
                }
                break;
            case 6203: // Zamorak boss
                if (absX < 2918 || absY < 5318 || absX > 2936 || absY > 5331) {
                    message("You can't attack the boss outside of the room.");
                    return true;
                }
                break;
            case 6260: // Bandos boss
                if (absX < 2864 || absY < 5351 || absX > 2876 || absY > 5369) {
                    message("You can't attack the boss outside of the room.");
                    return true;
                }
                break;
        }
        return false; // Can attack Npc
    }

    /**
     * Player saving and loading
     * No need for a "FileManager"
     */
    public void saveBackup() {
        try {
            saveCharacter("./data/characters/backups/" + username + ".dat");
        }
        catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    public void saveCharacter() {
        try {
            saveCharacter("./data/characters/mainsave/" + username + ".dat");
        }
        catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    public void saveCharacter(String s) {
        if (!playerLoaded)
            return;
        try {
            BufferedWriter bufferedwriter = new BufferedWriter(new FileWriter(s));
            bufferedwriter.write("[ACCOUNT]", 0, 9);
            bufferedwriter.newLine();
            bufferedwriter.write("username:", 0, 9);
            bufferedwriter.write(username, 0, username.length());
            bufferedwriter.newLine();
            bufferedwriter.write("password:", 0, 9);
            bufferedwriter.write(String.valueOf(Misc.stringToLong(password)), 0, String.valueOf(Misc
                    .stringToLong(password)).length());
            bufferedwriter.newLine();
            bufferedwriter.newLine();
            bufferedwriter.write("[CHARACTER]", 0, 11);
            bufferedwriter.newLine();
            bufferedwriter.write("new:", 0, 4);
            bufferedwriter.write(Boolean.toString(newPlayer), 0, Boolean.toString(newPlayer).length());
            bufferedwriter.newLine();
            bufferedwriter.write("height:", 0, 7);
            bufferedwriter.write(Integer.toString(heightLevel), 0, Integer.toString(heightLevel).length());
            bufferedwriter.newLine();
            bufferedwriter.write("absx:", 0, 5);
            bufferedwriter.write(Integer.toString(absX != -1 ? absX : 3087), 0,
                    Integer.toString(absX != -1 ? absX : 3087).length());
            bufferedwriter.newLine();
            bufferedwriter.write("absy:", 0, 5);
            bufferedwriter.write(Integer.toString(absY != -1 ? absY : 3503), 0,
                    Integer.toString(absY != -1 ? absY : 3503).length());
            bufferedwriter.newLine();
            bufferedwriter.write("rights:", 0, 7);
            bufferedwriter.write(Integer.toString(rights), 0, Integer.toString(rights).length());
            bufferedwriter.newLine();
            bufferedwriter.write("donor:", 0, 6);
            bufferedwriter.write(String.valueOf(donor), 0, String.valueOf(donor).length());
            bufferedwriter.newLine();
            bufferedwriter.write("energy:", 0, 7);
            bufferedwriter.write(Integer.toString(runEnergy), 0, Integer.toString(runEnergy).length());
            bufferedwriter.newLine();
            bufferedwriter.write("jailTimer:", 0, 10);
            bufferedwriter.write(Integer.toString(jailTimer), 0, Integer.toString(jailTimer).length());
            bufferedwriter.newLine();
            bufferedwriter.write("spellbook:", 0, 10);
            bufferedwriter.write(Integer.toString(spellbook), 0, Integer.toString(spellbook).length());
            bufferedwriter.newLine();
            bufferedwriter.write("muted:", 0, 6);
            bufferedwriter.write(Integer.toString(muteType), 0, Integer.toString(muteType).length());
            bufferedwriter.newLine();
            bufferedwriter.write("KC:", 0, 3);
            bufferedwriter.write(Integer.toString(KC), 0, Integer.toString(KC).length());
            bufferedwriter.newLine();
            bufferedwriter.write("DC:", 0, 3);
            bufferedwriter.write(Integer.toString(DC), 0, Integer.toString(DC).length());
            bufferedwriter.newLine();
            bufferedwriter.write("PVPPotential:", 0, 13);
            bufferedwriter.write(Double.toString(PVPPotential), 0, Double.toString(PVPPotential).length());
            bufferedwriter.newLine();
            bufferedwriter.write("kills:", 0, 6);
            bufferedwriter.write(Integer.toString(kills), 0, Integer.toString(kills).length());
            bufferedwriter.newLine();
            bufferedwriter.write("total kills:", 0, 12);
            bufferedwriter.write(Integer.toString(totalKills), 0, Integer.toString(totalKills).length());
            bufferedwriter.newLine();
            bufferedwriter.write("spending exp:", 0, 13);
            bufferedwriter.write(Integer.toString(spendingExperience), 0, Integer.toString(spendingExperience).length());
            bufferedwriter.newLine();
            bufferedwriter.write("last killed:", 0, 12);
            bufferedwriter.write(lastKilled, 0, lastKilled.length());
            bufferedwriter.newLine();
            bufferedwriter.write("degrade:", 0, 8);
            bufferedwriter.write(Integer.toString(degrade), 0, Integer.toString(degrade).length());
            bufferedwriter.newLine();
            bufferedwriter.write("spec amount:", 0, 12);
            bufferedwriter.write(Integer.toString(specAmount), 0, Integer.toString(specAmount).length());
            bufferedwriter.newLine();
            bufferedwriter.write("barrows:", 0, 8);
            bufferedwriter.write(Integer.toString(barrowsStage), 0, Integer.toString(barrowsStage).length());
            bufferedwriter.newLine();
            bufferedwriter.write("armadyl:", 0, 8);
            bufferedwriter.write(Integer.toString(armadylKills), 0, Integer.toString(armadylKills).length());
            bufferedwriter.newLine();
            bufferedwriter.write("bandos:", 0, 7);
            bufferedwriter.write(Integer.toString(bandosKills), 0, Integer.toString(bandosKills).length());
            bufferedwriter.newLine();
            bufferedwriter.write("saradomin:", 0, 10);
            bufferedwriter.write(Integer.toString(saradominKills), 0, Integer.toString(saradominKills).length());
            bufferedwriter.newLine();
            bufferedwriter.write("zamorak:", 0, 8);
            bufferedwriter.write(Integer.toString(zamorakKills), 0, Integer.toString(zamorakKills).length());
            bufferedwriter.newLine();
            bufferedwriter.newLine();
            bufferedwriter.write("[EQUIPMENT]", 0, 11);
            bufferedwriter.newLine();
            for (int i = 0; i < equipment.length; i++) {
                bufferedwriter.write("equipment:", 0, 10);
                bufferedwriter.write(Integer.toString(i), 0, Integer.toString(i).length());
                bufferedwriter.write("\t", 0, 1);
                bufferedwriter.write(Integer.toString(equipment[i]), 0, Integer.toString(equipment[i]).length());
                bufferedwriter.write("\t", 0, 1);
                bufferedwriter.write(Integer.toString(equipmentN[i]), 0, Integer.toString(equipmentN[i]).length());
                bufferedwriter.write("\t", 0, 1);
                bufferedwriter.newLine();
            }
            bufferedwriter.newLine();
            bufferedwriter.write("[LOOK]", 0, 6);
            bufferedwriter.newLine();
            bufferedwriter.write("gender:", 0, 7);
            bufferedwriter.write(Integer.toString(gender), 0, Integer.toString(gender).length());
            bufferedwriter.newLine();
            for (int j = 0; j < look.length; j++) {
                bufferedwriter.write("look:", 0, 5);
                bufferedwriter.write(Integer.toString(j), 0, Integer.toString(j).length());
                bufferedwriter.write("\t", 0, 1);
                bufferedwriter.write(Integer.toString(look[j]), 0, Integer.toString(look[j]).length());
                bufferedwriter.newLine();
            }

            bufferedwriter.newLine();
            bufferedwriter.write("[SKILLS]", 0, 8);
            bufferedwriter.newLine();
            for (int k = 0; k < skillLvl.length; k++) {
                bufferedwriter.write("skill:", 0, 6);
                bufferedwriter.write(Integer.toString(k), 0, Integer.toString(k).length());
                bufferedwriter.write("\t", 0, 1);
                bufferedwriter.write(Integer.toString(skillLvl[k]), 0, Integer.toString(skillLvl[k]).length());
                bufferedwriter.write("\t", 0, 1);
                bufferedwriter.write(Integer.toString(skillXP[k]), 0, Integer.toString(skillXP[k]).length());
                bufferedwriter.newLine();
            }

            bufferedwriter.newLine();
            bufferedwriter.write("[ITEMS]", 0, 7);
            bufferedwriter.newLine();
            for (int l = 0; l < items.length; l++)
                if (items[l] > 0) {
                    bufferedwriter.write("item:", 0, 5);
                    bufferedwriter.write(Integer.toString(l), 0, Integer.toString(l).length());
                    bufferedwriter.write("\t", 0, 1);
                    bufferedwriter.write(Integer.toString(items[l]), 0, Integer.toString(items[l]).length());
                    bufferedwriter.write("\t", 0, 1);
                    bufferedwriter.write(Integer.toString(itemsN[l]), 0, Integer.toString(itemsN[l]).length());
                    bufferedwriter.newLine();
                }

            bufferedwriter.newLine();
            bufferedwriter.write("[BANK]", 0, 6);
            bufferedwriter.newLine();
            for (int i1 = 0; i1 < bankItems.length; i1++)
                if (bankItems[i1] > 0) {
                    bufferedwriter.write("bank:", 0, 5);
                    bufferedwriter.write(Integer.toString(i1), 0, Integer.toString(i1).length());
                    bufferedwriter.write("\t", 0, 1);
                    bufferedwriter.write(Integer.toString(bankItems[i1]), 0, Integer.toString(bankItems[i1]).length());
                    bufferedwriter.write("\t", 0, 1);
                    bufferedwriter.write(Integer.toString(bankItemsN[i1]), 0, Integer.toString(bankItemsN[i1]).length());
                    bufferedwriter.newLine();
                }

            bufferedwriter.newLine();
            bufferedwriter.write("[FRIENDS]", 0, 9);
            bufferedwriter.newLine();
            for (int j1 = 0; j1 < friends.size(); j1++)
                if ((friends.get(j1)).longValue() > 0L) {
                    bufferedwriter.write("friend:", 0, 7);
                    bufferedwriter.write(Integer.toString(j1), 0, Integer.toString(j1).length());
                    bufferedwriter.write("\t", 0, 1);
                    bufferedwriter.write(Long.toString((friends.get(j1)).longValue()), 0, Long.toString((
                            friends.get(j1))).length());
                    bufferedwriter.newLine();
                }

            bufferedwriter.newLine();
            bufferedwriter.write("[EOF]", 0, 5);
            bufferedwriter.newLine();
            bufferedwriter.newLine();
            bufferedwriter.close();
        }
        catch (IOException ioexception) {
            System.out.println((new StringBuilder()).append("Error saving file: ").append(ioexception.getMessage()).toString());
            ioexception.printStackTrace();
        }
    }
    public String newPassword = "";
    public void loadCharacter() {
        String s = "";
        String s1 = "";
        String s3 = "";
        String as[] = new String[3];
        boolean flag = false;
        boolean newFile = false;
        int i = 0;
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader("./data/characters/mainsave/" + username + ".dat"));
        }
        catch (FileNotFoundException filenotfoundexception) {
            playerLoaded = true;
            password = newPassword;
            saveCharacter();
            System.out.println("New player registered: " + username);
            newFile = true;
            playerLoaded = false;
            //return;
        }
        if (newFile) {
            loadCharacter(); // Loop back and start the loading again
            return;
        }
        if (reader == null)
            return;

            try {
                s = reader.readLine();
            } catch (IOException ioexception) {
                System.out.println((new StringBuilder()).append(username).append(": error loading file.").toString());
                return;
            }
            do {
                    if (flag || s == null)
                        break;
                    s = s.trim();
                    int j = s.indexOf(":");
                    if (j > -1) {
                        String s2 = s.substring(0, j);
                        s2 = s2.trim();
                        String s4 = s.substring(j + 1);
                        s4 = s4.trim();
                        String as1[] = s4.split("\t");
                        switch (i) {
                            case 1: // '\001'
                                if (!s2.equals("username") && s2.equals("password"))
                                    password = Misc.longToString(Long.parseLong(s.substring(9)));
                                break;

                            case 2: // '\002'
                                if (s2.equals("new")) {
                                    newPlayer = Boolean.valueOf(s4);
                                } else if (s2.equals("height")) {
                                    tempHeight = Integer.parseInt(s4);
                                    tempHeight2 = Integer.parseInt(s4);
                                } else if (s2.equals("absx"))
                                    teleportToX = Integer.parseInt(s4) != -1 && Integer.parseInt(s4) != 0 ? Integer.parseInt(s4) : 3087;
                                else if (s2.equals("absy"))
                                    teleportToY = Integer.parseInt(s4) != -1 && Integer.parseInt(s4) != 0 ? Integer.parseInt(s4) : 3503;
                                else if (s2.equals("rights"))
                                    rights = Integer.parseInt(s4) != -1 ? Integer.parseInt(s4) : 0;
                                else if (s2.equals("donor"))
                                    donor = Boolean.valueOf(s4).booleanValue();
                                else if (s2.equals("energy"))
                                    runEnergy = Integer.parseInt(s4);
                                else if (s2.equals("jailTimer"))
                                	jailTimer = Integer.parseInt(s4);
                                else if (s2.equals("spellbook"))
                                    spellbook = Integer.parseInt(s4);
                                else if (s2.equals("muted"))
                                    muteType = Integer.parseInt(s4);
                                else if (s2.equals("KC"))
                                    KC = Integer.parseInt(s4);
                                else if (s2.equals("DC"))
                                    DC = Integer.parseInt(s4);
                                else if (s2.equals("PVPPotential"))
                                    PVPPotential = Double.valueOf(s4).doubleValue();
                                else if (s2.equals("kills"))
                                    kills = Integer.parseInt(s4);
                                else if (s2.equals("total kills"))
                                    totalKills = Integer.parseInt(s4);
                                else if (s2.equals("spending exp"))
                                    spendingExperience = Integer.parseInt(s4);
                                else if (s2.equals("last killed"))
                                    lastKilled = s4;
                                else if (s2.equals("degrade"))
                                    degrade = Integer.parseInt(s4);
                                else if (s2.equals("spec amount"))
                                    specAmount = Integer.parseInt(s4);
                                else if (s2.equals("barrows"))
                                    barrowsStage = Integer.parseInt(s4);
                                else if (s2.equals("armadyl"))
                                    armadylKills = Integer.parseInt(s4);
                                else if (s2.equals("bandos"))
                                    bandosKills = Integer.parseInt(s4);
                                else if (s2.equals("saradomin"))
                                    saradominKills = Integer.parseInt(s4);
                                else if (s2.equals("zamorak"))
                                    zamorakKills = Integer.parseInt(s4);
                                break;

                            case 3: // '\003'
                                if (s2.equals("equipment")) {
                                    equipment[Integer.parseInt(as1[0])] = Integer.parseInt(as1[1]);
                                    equipmentN[Integer.parseInt(as1[0])] = Integer.parseInt(as1[2]);
                                }
                                break;

                            case 4: // '\004'
                                if (s2.equals("gender"))
                                    gender = Integer.parseInt(s4);
                                else if (s2.equals("look"))
                                    look[Integer.parseInt(as1[0])] = Integer.parseInt(as1[1]);
                                break;

                            case 5: // '\005'
                                if (s2.equals("skill")) {
                                    skillLvl[Integer.parseInt(as1[0])] = Integer.parseInt(as1[1]);
                                    skillXP[Integer.parseInt(as1[0])] = Integer.parseInt(as1[2]);
                                }
                                break;

                            case 6: // '\006'
                                if (s2.equals("item")) {
                                    items[Integer.parseInt(as1[0])] = Integer.parseInt(as1[1]);
                                    itemsN[Integer.parseInt(as1[0])] = Integer.parseInt(as1[2]);
                                }
                                break;

                            case 7: // '\007'
                                if (s2.equals("bank")) {
                                    bankItems[Integer.parseInt(as1[0])] = Integer.parseInt(as1[1]);
                                    bankItemsN[Integer.parseInt(as1[0])] = Integer.parseInt(as1[2]);
                                }
                                break;

                            case 8: // '\b'
                                if (s2.equals("friend"))
                                    try {
                                        Long long1 = Long.valueOf(Long.parseLong(as1[1]));
                                        String ss = Misc.longToString(Long.parseLong(s.substring(9)));
                                                //  = Misc.longToString(Long.parseLong(s.substring(9)));
                                        friends.add(Misc.stringToLong(ss));
                                    }
                                    catch (Exception exception) {
                                        Misc.println(""+exception.getMessage());
                                        //Misc.print(""+exception.getMessage());
                                        System.out.println((new StringBuilder()).append("Couldn't load friends. Reason? ").append(exception.getMessage()).toString());
                                    }
                                break;
                        }
                    } else if (s.equals("[NEW SAVE FILE]") || s.equals("[ACCOUNT]"))
                        i = 1;
                    else if (s.equals("[CHARACTER]"))
                        i = 2;
                    else if (s.equals("[EQUIPMENT]"))
                        i = 3;
                    else if (s.equals("[LOOK]"))
                        i = 4;
                    else if (s.equals("[SKILLS]"))
                        i = 5;
                    else if (s.equals("[ITEMS]"))
                        i = 6;
                    else if (s.equals("[BANK]"))
                        i = 7;
                    else if (s.equals("[FRIENDS]"))
                        i = 8;
                    else if (s.equals("[EOF]")) {
                        try {
                            reader.close();
                        } catch (IOException ioexception2) {
                            System.out.println("Couldn't close file at end of method. Reason? " + ioexception2.getMessage());
                        }
                        System.out.println("[" + Misc.getDate() + "]" + username + ": File loaded [Rights: " + rights + "]");
                        playerLoaded = true; // Loaded, can now save safely
			saveBackup();
                    }
                    try {
                        s = reader.readLine();
                    } catch (IOException ioexception3) {
                        boolean flag1 = true;  // playerDisconnected = true;
                        return;
                    }
            } while (true);
            try {
                reader.close();
            } catch (IOException ioexception1) {
                System.out.println("Couldn't close file at end of method. Reason? " + ioexception1.getMessage());
            }
    }

    public void appendData(String s, String s1) {
        Object obj = null;
        try {
            FileWriter filewriter = new FileWriter((new StringBuilder()).append("./data/").append(s).toString(), true);
            BufferedWriter bufferedwriter = new BufferedWriter(filewriter);
            bufferedwriter.write(s1);
            bufferedwriter.newLine();
            bufferedwriter.flush();
            bufferedwriter.close();
            filewriter = null;
            bufferedwriter = null;
        }
        catch (Exception exception) {
        }
    }
}